//var = "idnhswtw"
function viewMyRecord() {
		document.location.href="Contact.aspx?contactAction=MYRECORD"
}

function viewMyRecordCheck() {
	if (checkDirty()) {
		document.location.href="Contact.aspx?contactAction=MYRECORD"
	}
}

function hideLeft() {
	if (top.document.getElementById('FRTOP').cols =="97,*") {	
		top.document.getElementById('FRTOP').cols = "0,*";
		document.all.collapse.src = "../images/collapse.gif";
		document.all.collapse.alt = "Show Menu";
	}else{
		top.document.getElementById('FRTOP').cols = "97,*";
		document.all.collapse.src = "../images/expand.gif";
		document.all.collapse.alt = "Full Screen";
	}
}

function hoverimg(obj, hvImg) {
	obj.src = "../images/" + hvImg;
}
	
function trimString(str){
			var strResult
			strResult = leftTrim(str)
			strResult = rightTrim(strResult)
			return strResult
}

function leftTrim(str) {
			var strResult = ""
			var flag = false
			var pos = 0
			var i = 0
			if (str.length > 0) {
	 			while ((i< str.length )&& (flag == false)){
	  				if (str.charAt(i)==" ") {i++
	  	 			}
	  				else {
	    				flag = true
					pos = i
					strResult = str.substring(pos,str.length)
					
	  				}	 
				}
			if (i == str.length) {return strResult;}	
			}

			return strResult;
}
	
function rightTrim(str) {
			var strResult = ""
			var flag = false
			var pos = str.length -1
			var i = str.length -1
			if (str.length >0) {
			while ((i >= 0) && (flag == false)) {
				if (str.charAt(i)==" ") {
					i--
				}
				else {
				flag = true
				pos = i
				strResult = str.substring(0,pos + 1)
				
				}
			}
			if (i == -1) {return strResult;}	
			} 

			return strResult
}

function testZipU(zip) {
    dateStr = zip;
	if (dateStr.length==5){
		str=dateStr.replace(/\D/g,"");
	       if (str.length==5)
			return true;
		else	
			return false;	
	}else if (dateStr.indexOf("-")==5){
	   str=dateStr.replace(/\D/g,"");
	   if (str.length==9) {
		return true;
	   }else
		return false;
	}else 
	
	  return false;
}

function checkZip(zipObj) {
	sVal = zipObj.value;
	if (!testZipU(sVal)) {
		alert("Invalid Zip format");
		zipObj.select();
		zipObj.focus();
		return false;
	}	
	return true;		
}

function defaultTab(id) { 
	tds = parent.frames[4].document.getElementsByTagName("td")
	for(i=0;i<tds.length;i++) {
		if(tds[i].className=="tab_hover")
			tds[i].className = "tab";
	}
	if (parent.frames[4].document.getElementById(id) != null) {
	     parent.frames[4].document.getElementById(id).className = "tab_hover";
	}
}

	
function openCompanyLookup(){
	if (document.forms[0].isDirty.value == "true") {
		if (confirm('You have unsaved data. Perform this quick search function will cause you lost unsaved data.\nClick OK to return to the form. Click Cancel to continue.')) {
			return false;

		}else{
			document.forms[0].isDirty.value = "false";
			parent.frames[0].document.forms[0].isDirty.value = "false";
		}
	}

	if (document.forms[0].CF_25.value != '') {
		document.forms[0].CF_25.disabled = false;
		document.forms[0].iStart.value = "1";
		document.forms[0].action="contact.aspx";
		document.forms[0].method="POST";
		document.forms[0].contactAction.value="COMPANY_LOOKUP";
		document.forms[0].submit();
	}
}

//load the blank page for the bottom frame. - Doan
function bottomblank() { 
	top.document.getElementById('FRRIGHT').rows = '318,*, 0';
	parent.frames[4].document.location.href="../html/blank.html";
	parent.frames[3].document.location.href="../html/mainwelcome.html";
}
//
function showasmoney(x) {
    x -= 0;
    x = (Math.round(x*100))/100;
    return (x == Math.floor(x)) ? x + '.00' : (  (x*10 == Math.floor(x*10)) ? x + '0' : x);
}

function gety(){
    if ((event.screenY+170) < screen.height)
       {return (event.screenY - 85);}
       else
       {return event.screenY-200;}
}

function getx(){
    if ((event.screenX+170) < screen.width)
       {return event.screenX-85;}
       else
       {return event.screenX-200;};
}

function setsave(){
   top.frames['tdata'].document.forms[0].elements['sv'].value='yes';
   document.forms[0].elements['save_button'].src='images/save_a.gif';
}

function dosave(){
   top.frames['tdata'].document.forms[0].elements['sv'].value='no';
   document.forms[0].submit();
}


function savemsg(){
   if (top.frames['tdata'].document.forms[0].elements['sv'].value=='yes') {
      if (confirm('Click OK to discard your changes. To save changes, click Cancel and then the Save button.')) {       
         top.frames['tdata'].document.forms[0].elements['sv'].value='no';
         return true;
         }
         else {
         return false;
         }
      }
      else {
      return true;
      }
} 

function isLeapYear(wdt) {
	return (wdt.getFullYear() % 4 == 0);
}

function getDaysInMonth(wdt) {
	switch(wdt.getMonth()) {
		//november
		case 10 : return 30;
		//april
		case 3  : return 30;
		//june
		case 5  : return 30;
		//september
		case 8  : return 30;
		//february
		case 1  :
			if (isLeapYear(wdt)) {return 29;}
			else {return 28;}
		//others
		default :
			return 31;
	}
}

function getDaysInPrevMonth(wdt) {
	switch(wdt.getMonth()) {
		//november
		case 11 : return -30;
		//april
		case 4  : return -30;
		//june
		case 6  : return -30;
		//september
		case 9  : return -30;
		//february
		case 2  :
			if (isLeapYear(wdt)) {return -29;}
			else {return -28;}
		//others
		default :
			return -31;
	}
}

function newItem(dropdown) {
   ws=prompt("Field Value:", dropdown.options[dropdown.selectedIndex].text);
   if (ws != null) {
      if (ws.length > 0) {
         var wOption = new Option(ws, ws);
         x = dropdown.length;
         dropdown.options[x] = wOption;
         dropdown.options[x].selected = 1;
      }
   }
}

function isZero(wVal) {
   if (wVal == 0) {
      return true; } else {   
      return false;} 
   }

function CalcTotal() {
   x=document.forms[0].elements['units'].value;
   y=document.forms[0].elements['unitprice'].value;
   z=document.forms[0].elements['amount'].value;

   if (isZero(z)) {
      t=x*y;
      if (!isNaN(t)) {
         document.forms[0].elements['amount'].value=showasmoney(x*y);
         }
      } 

   if (isZero(y)) {
      t=z/x;
      if (!isNaN(t)) {
         document.forms[0].elements['unitprice'].value=showasmoney(z/x);
         }
      } 

   if (isZero(x))  {
      t=z/y;
      if (!isNaN(t)) {
         document.forms[0].elements['units'].value=z/y;
         }
      }
   }


function DateRecalc(wedit,wx) {
   ws = wedit.value;
   wdt = new Date(ws);
   if (wx > 0) {
      if (wx == 30) {wx = getDaysInMonth(wdt);}
      } 
      else {
      if (wx == -30)  {wx = getDaysInPrevMonth(wdt);}
      }
   wdt.setTime(wdt.getTime()+(wx*1000*60*60*24));
   wedit.value = wdt.getMonth()+1+"/"+wdt.getDate()+"/"+wdt.getYear();
   }
