/*
'======================================================================
' AUTHOR: Tim Sewell
' OVERVIEW: 
' Javascript functions
'
' MODIFICATION DETAILS (LAST 2)
' LAST EDITED: Tim Sewell - 28/04/2004
' COMMENTS:
' 
'======================================================================
*/

/*======================================================================
								OPEN POPUP WINDOWS
======================================================================*/

var wHeight = screen.height
var wWidth = screen.width


function popupMainWindow(url,height,width) 
{
	var isHeight=Number(height);
	var isWidth=Number(width);
	var wTop = (wHeight - isHeight) / 2
	var wLeft = (wWidth - isWidth) / 2
	mainWindow  =   window.open(url,"mainWindow",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+isWidth+',height='+isHeight+',top='+wTop+',left='+wLeft);
	mainWindow.focus();
}

function popupMainWindow1(url,height,width) {
  var isHeight=Number(height);
  var isWidth=Number(width);
  var wTop = (wHeight - isHeight) / 2
  var wLeft = (wWidth - isWidth) / 2
  mainWindow1  =   window.open(url,"mainWindow1",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+isWidth+',height='+isHeight+',top='+wTop+',left='+wLeft);
  mainWindow1.focus();
}

function centerScreen(xWidth,xHeight)
{
		window.resizeTo(xWidth,xHeight);
		var wHeight = screen.height-xHeight;
  		var wWidth = screen.width-xWidth;
  		window.moveTo(wWidth/2,wHeight/2);
}

/*======================================================================
								CHECK FOR DIGITS
======================================================================*/

function isDigits(str) {
	var i
	for (i = 0; i < str.length; i++) {
		mychar = str.charAt(i)
		if ((mychar < "0" || mychar > "9") && mychar !=".")
			return false;
	}
	return true;
}

/*======================================================================
								CHECK FOR VALID EMAIL
======================================================================*/

function checkemail(s)
{
    var str = s;
    var filter=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
    if (filter.test(str))
        testresults=true
    else
    {
        alert("Please input a valid email address!")
        testresults=false
    }
    return (testresults)
}

function VeryfyEmail(emailStr) 
   {
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) 
	{
		//alert("Email is invalid");
		return false;
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	if (user.match(userPat)==null) 
	{
	    //alert("Email is invalid");
	    return false;
	}
	
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) 
	{
		  for (var i=1;i<=4;i++) 
		  {
		    if (IPArray[i]>255) 
		    {
		        //alert("Email is invalid");
				return false;
		    }
	      }
	    return true
	}
	var domainArray=domain.match(domainPat)
	if (domainArray==null) 
	{
		//alert("Email is invalid")
	    return false
	}
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
	    domArr[domArr.length-1].length>3) 
	    {
		   //alert("Email is invalid");
		   return false;
		}
	if (len<2) 
	{ //>
	   //alert("Email is invalid");
	   return false;
	}
	
	return true;
}

function checkDataTable()
{
	if(TheForm.Strtype.value==''){alert("Please select the type of data table you would like to upload."); return false;}
}


/*======================================================================
								TOGGLE functions for CMS
======================================================================*/


function visibilityToggle(id,getImg,framename,url) 
{
	var winLoc = window.frames[framename].location
	winLoc = new String(winLoc)

	var el = document.getElementById(id).style; 
	var img = document.getElementById(getImg);

	if(el.display == "none") 
	{ 
		if (url.search(/winLoc/i)==-1)
		{
			window.frames[framename].location.href=url
		}
		el.display = "block";
		img.className = 'clsPartRight'
	} 
	else if(el.display == "block") 
	{ 
		el.display = "none";
		img.className = 'clsPartRightHidden'
	} 
} 



function visibilityToggleNew(id,getImg,framename,url,color,close) 
{
	var winLoc = window.frames[framename].location
	winLoc = new String(winLoc)

	var el = document.getElementById(id).style; 
	var img = document.getElementById(getImg);

	if (close == 0)
	{
			if (url.search(/winLoc/i)==-1)
			{
				//window.frames[framename].location.href=url
				window.frames[framename].location.href=url;
			}
			el.display = "block";
			img.className = 'clsPartRight'
	}
	else
	{
		if (el.display == "none")
		{ 
			if (url.search(/winLoc/i)==-1)
			{
				window.frames[framename].location.href=url
			}
			el.display = "block";
			img.className = 'clsPartRight'
		} 
		else if(el.display == "block")
		{ 
			el.display = "none";
			img.className = 'clsPartRightHidden'
		}
	}
} 

function mysearch()
	{
		f1.submit();
	}
function mysearchOrders()
	{
		s1.submit();
	}

function setWarranty(optname,prodid)
	{
		f1.action='/ecommerce.asp?step=2&wname='+prodid+'&optname='+optname;
		f1.submit();
	}
function setWarrantyO(optname,prodid)
	{
		f1.action='/memberArea.asp?step=5&wname='+prodid+'&optname='+optname;
		f1.submit();
	}
function myrestore(table)
	{
		var option = confirm("Are you sure you wish to restore this table?\n\nIf you select 'OK', then all data within will be permanently deleted.");
		
		if (option==true)
		{
			if(table==1){f1.action='cms_popup.asp?step=17&substep=2';}
			else if(table==2){f1.action='cms_popup.asp?step=17&substep=3';}
			else if(table==3){f1.action='cms_popup.asp?step=17&substep=4';}
			else if(table==4){f1.action='cms_popup.asp?step=17&substep=5';}
			else if(table==5){f1.action='cms_popup.asp?step=17&substep=6';}
			else if(table==6){f1.action='cms_popup.asp?step=17&substep=7';}
			else if(table==7){f1.action='cms_popup.asp?step=17&substep=8';}
			else if(table==8){f1.action='cms_popup.asp?step=17&substep=9';}
		}
		f1.submit();
	}

function Addbuttons(num)
{
var x;
for(i=0;i<10;i++)
	{
	x="F1.Q"+(i+1)+".style.visibility='hidden';";
	eval(x);
	}
for(i=0;i<num;i++)
	{
	x="F1.Q"+(i+1)+".style.visibility='visible';";
	eval(x);
	}
}

function checkActive()
{
	if(document.F1.active[0].checked == true)
	{
		document.F1.archived[1].checked = true;
	}
	if(document.F1.active[1].checked == true)
	{
		document.F1.archived[0].checked = true;
	}
}

function checkArchived()
{
	if(document.F1.archived[0].checked == true)
	{
		document.F1.active[1].checked = true;
	}
	if(document.F1.archived[1].checked == true)
	{
		document.F1.active[0].checked = true;
	}


}