function Createlink(obj)
{
	var myArray = obj.split(',');
	var size = myArray.length;
	if ( (obj == "") || (obj == "null") || (size < 6) )
	{
		return alert ("insufficient parameter");
	}
	var path		=	myArray[0];
	var productId	=	myArray[1];
	var target		=	myArray[2];
	var external	=	myArray[3];
	var height		=	myArray[4];
	var width		=	myArray[5];

	Loadpage(path, productId, target, external,height,width);
}

function openNewWin(url,winName,winProp,lid,ipath){
 newWin = window.open(url,winName,winProp);
 newWin.focus();
}

function Loadpage(path, tabId, target, external, height, width) {
	
	if ( (!path) || (trim(path) == "") ) {
		return alert ("path cannot be empty or null");
	}

	var queryStringIndex = path.indexOf("?");
	var normalizedPath = (queryStringIndex > 0)?path.substring(0, queryStringIndex):path;

	var isWebServerFile = false;
	var isExternalSite = false;
	height = ( (height == "") || (height == "null") || (!height) )?"534" :height;
	width =  ( (width  == "") || (width  == "null") || (!width)  )?"650" :width;
	tabId =  ( (tabId == "" ) || (tabId == "null" ) || (!tabId)  )?"home":tabId;
	
	tabId = tabId.replace(/[^A-Za-z0-9,]+/, "");
	
	if(normalizedPath.indexOf("/global_docs/") == 0 || normalizedPath.indexOf("/portal/") == 0 || normalizedPath.indexOf("http://") >= 0 || normalizedPath.indexOf("https://") >= 0) {
		isWebServerFile = true;
	}
	if(external == "Y" || external == "y"){
    	isExternalSite = true;
  	}
	
	var isAppLink = false;
	if(path.indexOf(".do") >= 0) {
		isAppLink = true;
	}	
    
	if (isExternalSite) {
	   confirnbox(path,target, height, width);
	}
  	else if (target == "0" || target == "null" || target == ""){
	  	if(!isWebServerFile && !isAppLink) {
	  		path = "/AUCRD/APPS/portal/loadPage.do?tabId="+tabId+ "&path="+path;
	    }
	    else if(isAppLink){
	    	path = "/AUCRD"+path;
	    }
    	top.location.href = path;
  	}
	else if (target == "1") {		
		var param = "left=95" + "," + "top=11" + "," + "width=" + width + "," + "height=" + height + "," +"location=yes" + "," +"status=no" +"," +"toolbar=no" + "," + "menubar=no" + "," + "scrollbars=yes";
		if(!isWebServerFile && !isAppLink) {
			path = "/AUCRD/APPS/portal/loadPage.do?tabId="+tabId+ "&path="+path;
	    }
	    else if(isAppLink){
	    	path = "/AUCRD"+path;
	    }  	
		window.open(path, "NewWinDow", param);
	}
	else if (target == "2") {
		var param = "left=95" + "," + "top=11" + "," + "width=" + width + "," + "height=" + height + "," +"location=yes" + "," +"status=yes" +"," +"toolbar=yes" + "," + "menubar=yes" + "," + "scrollbars=yes,resizable=yes";
		if(!isWebServerFile && !isAppLink) {
			path = "/AUCRD/APPS/portal/loadPage.do?tabId="+tabId+ "&path="+path;
	    }
	    else if(isAppLink){
	    	path = "/AUCRD"+path;
	    } 	
		window.open(path, "NewWinDow", param);			
	}
	else if (target == "3") {		
		if(!isWebServerFile && !isAppLink) {
			path = "/AUCRD/APPS/portal/loadPage.do?tabId="+tabId+ "&path="+path;
	    }
	    else if(isAppLink){
	    	path = "/AUCRD"+path;
	    }
		linkParentAndCloseSelf(path);
	}
}

function LoadAppPage(path, tabId, target, external, height, width){
	if ( (!path) || (trim(path) == "") ) {
		return alert ("path cannot be empty or null");
	}

	height = ( (height == "") || (height == "null") || (!height) )?"534" :height;
	width =  ( (width  == "") || (width  == "null") || (!width)  )?"650" :width;
	tabId =  ( (tabId == "" ) || (tabId == "null" ) || (!tabId)  )?"home":tabId;
	
	tabId = tabId.replace(/[^A-Za-z0-9,]+/, "");
    
 	if (target == "0" || target == "null" || target == ""){
 		path = "/AUCRD/APPS/portal/LoadAppPage.do?tabId="+tabId+ "&path="+path; 
	  	top.location.href = path;
	}
	else if (target == "1") {		
		var param = "left=95" + "," + "top=11" + "," + "width=" + width + "," + "height=" + height + "," +"location=yes" + "," +"status=no" +"," +"toolbar=no" + "," + "menubar=no" + "," + "scrollbars=yes";
    	path = "/AUCRD/APPS/portal/LoadAppPage.do?tabId="+tabId+ "&path="+path;
		window.open(path, "NewWinDow", param);
	}
	else if (target == "2") {
		var param = "left=95" + "," + "top=11" + "," + "width=" + width + "," + "height=" + height + "," +"location=yes" + "," +"status=yes" +"," +"toolbar=yes" + "," + "menubar=yes" + "," + "scrollbars=yes,resizable=yes";
		path = "/AUCRD/APPS/portal/LoadAppPage.do?tabId="+tabId+ "&path="+path;
		window.open(path, "NewWinDow", param);			
	}
	else if (target == "3") {		
    	path = "/AUCRD/APPS/portal/LoadAppPage.do?tabId="+tabId+ "&path="+path;
		linkParentAndCloseSelf(path);
	}
}

function confirnbox(path,target, height, width)
{
var name = confirm("You are now leaving the Card Services Australia website and entering a third party website. \n Any information you may provide on the third party website shall be subject to the confidentiality and security terms of such website and not the privacy policies of Card services Australia, and Card services Australia shall not bear any responsibility for any unauthorised disclosure or breach of confidentiality in relation to such information provided. \n Furthermore any link to a third party website contained herein does not constitute an endorsement by Card services Australia of such third party, their website or their products and/or services, and Card services Australia also makes no warranties as to the content of such website.\n Would you like to continue?")
if (name == true) 
{
if (target == "1")
{
var parm = "left=95" + "," + "top=11" + "," + "width=" + width + "," + "height=" + height + "," +"location=yes" + "," +"status=no" +"," +"toolbar=no" + "," + "menubar=no" + "," + "scrollbars=yes";
window.open(path,'NewWinDow', parm);
return ;
}
else if(target == "2")
{
var parm = "left=95" + "," + "top=11" + "," + "width=" + width + "," + "height=" + height + "," +"location=yes" + "," +"status=yes" +"," +"toolbar=yes" + "," + "menubar=yes" + "," + "scrollbars=yes,resizable=yes";
window.open(path,'NewWinDow', parm);
return;
}
else
{
window.location=path;
}
}
else
{
return ;
}
}
function trim(inputString) {
var newInputString = replace(inputString,'%20',' ');  
if (typeof newInputString != "string") { return newInputString; }
var retValue = newInputString;
var ch = retValue.substring(0, 1);
while (ch == " ") { 
retValue = retValue.substring(1, retValue.length);
ch = retValue.substring(0, 1);
}
ch = retValue.substring(retValue.length-1, retValue.length);
while (ch == " ") { 
retValue = retValue.substring(0, retValue.length-1);
ch = retValue.substring(retValue.length-1, retValue.length);
}
while (retValue.indexOf(" ") != -1) { 
retValue = retValue.substring(0, retValue.indexOf(" ")) + retValue.substring(retValue.indexOf(" ")+1, retValue.length); 
}
return retValue; 
}
function replace(string,text,by) {
var strLength = string.length, txtLength = text.length;
if ((strLength == 0) || (txtLength == 0)) 
return string;
var i = string.indexOf(text);
if ((!i) && (text != string.substring(0,txtLength))) return string;
if (i == -1) return string;
var newstr = string.substring(0,i) + by;
if (i+txtLength < strLength)
newstr += replace(string.substring(i+txtLength,strLength),text,by);
return newstr;
}

