//-----------------------------------------------------------------
function printPage(pagetitle, currentsite, cmd_company) {
//-----------------------------------------------------------------

	var sPrint = 'Print';
	var sClose = 'Close';


	var da = (document.all) ? 1 : 0;
	var pr = (window.print) ? 1 : 0;

	if(!pr)
		return;

	var printArea = document.getElementById("mainareadiv");

	if (printArea == null) {
		if (da) {
			printArea = document.all.mainareadiv;
		}
	}

	if (printArea) {
		var sStart = '<html>';
			sStart += '<head><title>' + pagetitle + '</title>';
			sStart += '<link href="/marketroot/js/main_'+ cmd_company +'.css" rel="stylesheet" type="text/css" /></head>';
			sStart += '<body onload="javascript:window.print();" style="margin: 10px;">';
			
		var sStop = '<div class="printerFriendlyFooter">';
			sStop += '<a class="button" onclick="window.print(); return false;" href="#">' + sPrint + '</a>&#160;';
			sStop += '<a class="button" onclick="window.close(); return false;" href="#">' + sClose + '</a>';
			sStop += '</div>';
			sStop += '</body></html>';

		var w = window.open('','printWin','width=800,height=600,scrollbars=yes resizable=yes');
		wdoc = w.document;
		wdoc.open();
		sStart += printArea.innerHTML
		wdoc.write(sStart) ;
		wdoc.writeln( sStop );
		wdoc.close();
	}
}

function getDocHeight(doc) {
  var docHt = 0, sh, oh;
  if (doc.height) docHt = doc.height;
  else if (doc.body) {
    if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
    if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
    if (sh && oh) docHt = Math.max(sh, oh);
  }
  return docHt;
}
function setBackOfficeIframeHeight(iframeName,temp) {
	
	if(temp=="0"){

	  var iframeWin = window.frames[iframeName];

	  var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
	  if ( iframeEl && iframeWin ) {
	    iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous
	    var docHt = getDocHeight(iframeWin.document);
	    // need to add to height to be sure it will all show
	    if (docHt) iframeEl.style.height = "0px";
	  }
	}
	else if(temp!=""){

	  var iframeWin = window.frames[iframeName];

	  var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
	  if ( iframeEl && iframeWin ) {
	    iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous
	    var docHt = getDocHeight(iframeWin.document);
	    // need to add to height to be sure it will all show
	    if (docHt) iframeEl.style.height = temp  +"px";
	  }
	 }

}
function setIframeHeight(iframeName) {
  var iframeWin = window.frames[iframeName];
  var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
  if ( iframeEl && iframeWin ) {
    iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous
    var docHt = getDocHeight(iframeWin.document);
    // need to add to height to be sure it will all show
    if (docHt) iframeEl.style.height = docHt + 30 + "px";
  }
}

function loadIframe(iframeName, url) {
  if ( window.frames[iframeName] ) {
    window.frames[iframeName].location = url;
    return false;
  }
  else return true;
}
function SetCookie(name, value, expires, path, domain)
{
  document.cookie = "username="+escape('##AM_FULLNAME##') + '; path=/';
}

function getexpirydate( nodays){
var UTCstring;
Today = new Date();
nomilli=Date.parse(Today);
Today.setTime(nomilli+nodays*24*60*60*1000);
UTCstring = Today.toUTCString();
return UTCstring;
}
function getcookie(cookiename) {

 var cookiestring=""+document.cookie;

 var index1=cookiestring.indexOf(cookiename);
 if (index1==-1 || cookiename=="") return "";
 var index2=cookiestring.indexOf(';',index1);
 if (index2==-1) index2=cookiestring.length;
 return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}

function setcookies(name,value,duration){

cookiestring=name+"="+escape(value)+";EXPIRES="+getexpirydate(duration)+"+ '; path=/'";
document.cookie=cookiestring;
if(!getcookie(name)){
return false;
}
}

function delete_Cookie(name, path, domain) {
if (getcookie(name)) {
	path ="/";
	document.cookie = name + "=" +
( (path)? ";path=" + path : "") +
( (domain)? ";domain=" + domain : "") +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
open_window('setcookies',"/marketroot/marketroot/setcookies.php?logout=1" ,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=250,height=250")
}
}

function goSetHeight() {
  if (parent == window) return;
  // arg: id of iframe element this doc is to be loaded into
  else
  {
  parent.setIframeHeight('ifrm');
  parent.parent.setIframeHeight('ifrm');
 }
}
function open_window(win_name,the_url, args)
{
  if (args == null)
     window.open(the_url,win_name,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=500,height=300')
  else
     window.open(the_url,win_name,args)
}

function check_email_friend_form(form)
{
  return true;
}


function do_submit(frm)
{
   frm.submit();
   return true;
}

function check_decision(message, url)
{
   if(confirm(message)) location.href = url;
}

function do_reset(frm)
{
   frm.reset();
   return true;
}

function check_form_searchform(frm)
{
   if (frm.keyword1.options[frm.keyword1.selectedIndex].value == '')
   {
      return false;
   }
}

function is_passwd_ok(s)
{
  if (s == "")
  {
     alert("Please enter Password.");
     return false;
  }
  if (s.length < 6)
  {
     alert("Minimum Password length is 6");
     return false;
  }
  if (s.length > 16)
  {
     alert("Maximum Password length is 16");
     return false;
  }
}

function checkform_mrspro_reg(frm)
{
  if (frm.C_LOGIN_ID.value == "")
  {
     alert("Please enter Login.");
     frm.C_LOGIN_ID.focus();
     return false;     
  }
  if (is_passwd_ok(frm.C_PASSWD.value) == false)
  {
     frm.C_PASSWD.focus();
     return false;
  }
  if (is_passwd_ok(frm.C_PASSWD2.value) == false)
  {
     frm.C_PASSWD2.focus();
     return false;
  }
  return true;
}

function enterLivePerson(aname, gname, re, name)
{
	window.name = "lp_parent";
	var url = "http://infoloan.client.liveperson.net/user.asp?aname=" + aname + "&gname=" + gname + "&RE=" + re + "&name=" + name;
	var hWnd = window.open(url,"live_person","width=300,height=350,resizable=yes,scrollbars=yes");
	if (hWnd != null)
	{
		if (hWnd.opener == null)
		{
			hWnd.opener = self; window.name = "home"; hWnd.location.href=url;
		}
	}
}

function openDialpad()
{
  var browserParsed = navigator.appVersion.substring (0,4);
  var browserName = navigator.appName; 

  if (browserName == "Netscape" && browserParsed < 4.06){
    alert("Netscape " + browserParsed + " is not supported");
    return false;
  }
  if (navigator.platform != "Win32") {
    alert(navigator.platform + " is not supported.")
    return false 
  }	      
  if (!navigator.javaEnabled()) {
    alert("Java should be enabled to use Dialpad");
    return false;
  }

  window.open('http://www.dialpad.com/cgi-bin/launch.pl',
   'Dialpad', 'scrollbars=no,resizable=no,width=420,height=370');
  return false;
}

function getCardType(number)
{ 
    // input: ccnum - creditcard number
    // if validated, return the type of card ()
    // if it is an unknown or invalid number return "- unknown-" 
    // Validation of Primary Account Number - LUHN Formula (Mod 10) (3/96)
    // CRITERIA
    // 1. number prefix
    // 2. number of digits
    // 3. mod10  (for all but enRoute which uses only 1 & 2)
    // Card Type		 Prefix 	    Length	Check-Digit Algoritm
    // MC			 51 - 55	    16		mod 10
    // VISA			 4		    13, 16	mod 10
    // AMX			 34, 37 	    15		mod 10
    // Diners Club/Carte Blanche 300 - 305, 36, 38  14		mod 10 
    // Discover 		 6011		    16		mod 10
    // enRoute			 2014, 2149	    16		- any -
    // JCB			 3			16	    mod 10
    // JCB			 2131, 1800		15	    mod 10

    var unknownCardType = "na";
    var cctype = unknownCardType;

    if (number == null
	|| number == "") {
      cctype = unknownCardType;
      return cctype;
    }
    
    var cclen = number.length;

    // first determine the type of card: MC, VISA, AMX, etc.
    // i.e. test prefix and then number of digits
    
    if (cclen == 0 
	|| cclen < 4 
	|| cclen > 16) {
      cctype = unknownCardType;
      return cctype; 
    }

    var prefix1 = number.substring(0,1);
    var prefix2 = number.substring(0,2);
    var prefix3 = number.substring(0,3);
    var prefix4 = number.substring(0,4);

    cctype = unknownCardType;

    if (prefix1 == 4 && (cclen == 16 || cclen == 13)) {
      cctype = "VISA";
    }

    if (prefix2 > 50 && prefix2 < 56 && cclen == 16) {
      cctype = "MASTERCARD";
    }

    if ((prefix2 == 34 || prefix2 == 37) && cclen == 15 ) {
      cctype = "American Express";
    }

    if ((prefix4 == 2014 || prefix4 == 2149) && cclen == 15 ) {
      cctype = "enRoute";
	  /* any number for enRoute */
	  return cctype;
    }

    if ((prefix2 == 36 || prefix2 == 38) && cclen == 14 ) {
      cctype = "Diners Club/Carte Blanche";
    }

    if (prefix3 > 299 && prefix3 < 306 && cclen == 14) {
      cctype = "Diners Club/Carte Blanche";
    }

    if (prefix4 == 6011 && cclen == 16) {
      cctype = "Discover";
    }

    if ((prefix4 == 2131 || prefix4 == 1800) && cclen == 15) {
      cctype = "JCB";
    }

    if (prefix1 == 3 && cclen == 16) {
      cctype = "JCB";
    }

    // mod10 - sum every digit starting with the RIGHT-MOST digit
    // on alternate digits (starting with the NEXT-TO-THE-RIGHT-MOST digit)
    // sum all digits in the result of TWO TIMES the alternate digit 
    // RATHER than the original digit itself

    var sum = 0;
    var alt = 0;
    for (var i=(cclen - 1);i>=0; i--) {
      if (alt == 1) {
	var digits = number.charAt(i) * 2;
	if (digits > 9) digits -= 9;
	sum += digits;
	alt = 0;
      } 
      else {
	sum = sum + parseInt(number.charAt(i));
	alt = 1;
      }
    }
    if ((sum%10) == 0) {
      return cctype;
    } 
    else {
      cctype = unknownCardType;
      return cctype; 
    }
}

function isExpired(year,month) 
{
  var today=new Date();
  var curmon=today.getMonth() +1;
  var curyr=today.getFullYear();
  if (year < curyr) return true;
  if (year == curyr) {
    if (month < curmon) return true
  }
  return false;
}

function cf_acmg_auscc(f)
{
  if (f.no_cccheck.value == "true") {
    return true;
  }

  if (f.aus_ccno.value == "") {
    alert("Please enter credit card number.");
    f.aus_ccno.focus();
    return false;    
  }
  var cctype = getCardType(f.aus_ccno.value);
  if ( cctype == null || cctype == "na") {
    alert("Invalid credit card number.");
    f.aus_ccno.focus(); 
    return false;
  }
  if (isExpired(f.aus_ccexpyr.options[f.aus_ccexpyr.selectedIndex].value
	       ,f.aus_ccexpmo.options[f.aus_ccexpmo.selectedIndex].value) == true) {
    alert("Credit card expired.");
    f.aus_ccexpmo.focus();    
    return false;
  }
  return true;
}

function cf_acmg_scocc(f)
{
  if (f.sco_cctype.value != "1" &&
      f.sco_cctype.value != "2" &&
      f.sco_cctype.value != "3" &&
      f.sco_cctype.value != "11" &&
      f.sco_cctype.value != "12") {
    return true;
  }

  if (f.sco_ccno.value == "") {
    alert("Please enter credit card number.");
    return false;    
  }
  
  if (f.sco_ccvv.value == "") {
    alert("Please enter credit card cvv.");
    return false;    
  }
  
  if (f.sco_ccname.value == "") {
    alert("Please enter credit card name.");
    return false;    
  }
  
  if (true) {
    var cctype = getCardType(f.sco_ccno.value);
    if ( cctype == null || cctype == "na") {
      alert("Invalid credit card number.");
      //f.sco_ccno.focus();	
      return false;
    }
  }
  if (isExpired(f.sco_ccexpyr.value
	       ,f.sco_ccexpmo.value) == true) {
    alert("Credit card expired.");
    //f.sco_ccexpmo.focus();    
    return false;
  }
  return true;
}

function moveModule(o_col, d_col) 
{
  o_sl = document.fm[o_col].selectedIndex;
  d_sl = document.fm[d_col].length;
  if (o_sl != -1 && document.fm[o_col].options[o_sl].value > "") {
    oText = document.fm[o_col].options[o_sl].text;
    oValue = document.fm[o_col].options[o_sl].value;
    document.fm[o_col].options[o_sl] = null;
    document.fm[d_col].options[d_sl] = new Option (oText, oValue, false, true);
  } else {
    alert("Please select a item first");
  }
}  

function orderModule(down, col) 
{
  sl = document.fm[col].selectedIndex;
  if (sl != -1 && document.fm[col].options[sl].value > "") {
    oText = document.fm[col].options[sl].text;
    oValue = document.fm[col].options[sl].value;
    if (document.fm[col].options[sl].value > "" && sl > 0 && down == 0) {
      document.fm[col].options[sl].text = document.fm[col].options[sl-1].text;
      document.fm[col].options[sl].value = document.fm[col].options[sl-1].value;
      document.fm[col].options[sl-1].text = oText;
      document.fm[col].options[sl-1].value = oValue;
      document.fm[col].selectedIndex--;
    } else if (sl < document.fm[col].length-1 && document.fm[col].options[sl+1].value > "" && down == 1) {
      document.fm[col].options[sl].text = document.fm[col].options[sl+1].text;
      document.fm[col].options[sl].value = document.fm[col].options[sl+1].value;
      document.fm[col].options[sl+1].text = oText;
      document.fm[col].options[sl+1].value = oValue;
      document.fm[col].selectedIndex++;
    }
  } else {
    alert("Please select a item first");
  }
}

function xMod(col) 
{
  req = "";
  sl = document.fm[col].selectedIndex;
  if (sl != -1 && document.fm[col].options[sl].value > "") {
    if (req.indexOf(document.fm[col].options[sl].value) > -1) {
      alert ("You may not delete a required corporate item.");
    } else {
      if (confirm("This will delete the selected item.")) {
	if (document.fm[col].options[sl].value!=".none") {
	  if (document.fm[col].length==1) {
	    document.fm[col].options[0].text="";
	    document.fm[col].options[0].value=".none";
	  } else {
	    document.fm[col].options[sl]=null; 
	  } 
	} else {
	  alert("Please select a item first");
	}
      }
    }
  }
}

function doSub() 
{
  layout = "N0N1";
  for (i=0; i < layout.length; i++) {
    if (layout.substr(i,1) == 'N' || layout.substr(i,1) == 'W') {
      col = layout.substr(i,2); 
      document.fm[col + "_lst"].value = makeList(col);
    }
  }
  return true;
}

function makeList(col) 
{
  val = "";
  for (j=0; j<document.fm[col].length; j++) {
    if (val > "") { val += ","; }
    if (document.fm[col].options[j].value > "") val += document.fm[col].options[j].value;
  } 
  return val;
}

function sub_layout(layout) {
  document.fm['.commit'][0].value="";
  document.fm['.layout'].value=layout;
  doSub();
  document.fm.submit();
}

/* Alert Messages */
function demo()
{
  alert("This function has been disabled for the demo.");
}

function previewMode()
{
  alert("This function is not available in Preview Mode.");
}

function SwitchMenu(obj){
	if(document.getElementById){

	var el = document.getElementById(obj);
	var ar = document.getElementById("masterdiv").getElementsByTagName("span"); //DynamicDrive.com change

	if(el.style.display != "block"){ //DynamicDrive.com change
			for (var i=0; i<ar.length; i++){
			   // alert(ar[i].className)
				//if (ar[i].className!="submenu") //DynamicDrive.com change
			//	ar[i].style.display = "block";
			}
			el.style.display = "block";
		}else{
			el.style.display = "block";
		}
	}
}
function funcvisible(prod,price){

    //var prod =##PRODUCT_CODE##;
   var str =eval(prod)
    	SwitchMenu(prod);

}



function MM_swapImgRestore()
{ //v3.0
  	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages()
{ //v3.0
  	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d)
{ //v4.01
  	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage()
{ //v3.0
  	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->

function hidestatus()
{
	window.status=''
	return true
}

function getObject(obj) {
  var theObj;
  if(document.all) {
    if(typeof obj=="string") {
      return document.all(obj);
    } else {
      return obj.style;
    }
  }
  if(document.getElementById) {
    if(typeof obj=="string") {
      return document.getElementById(obj);
    } else {
      return obj.style;
    }
  }
  return null;
}
//Contador de caracteres.
function Contar(entrada,salida,texto,caracteres) {
  var entradaObj=getObject(entrada);
  var salidaObj=getObject(salida);
  var longitud=caracteres - entradaObj.value.length;
  if(longitud <= 0) {
    longitud=0;
    texto='<span class="disable"> '+texto+' </span>';
    entradaObj.value=entradaObj.value.substr(0,caracteres);
  }
  salidaObj.innerHTML = texto.replace("{CHAR}",longitud);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

if (document.layers)
document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT)
document.onmouseover=hidestatus
document.onmouseout=hidestatus
