//break out of frames, if framed site tries to link to GC 
if (top.frames.length!=0) top.location=self.document.location;


browser = navigator.appName;
version = navigator.appVersion;
os = navigator.platform;
ie = "Microsoft Internet Explorer";
nn = "Netscape";
document.write('<test tag browser=' + browser + 'version=' + version + ' >');

//Code For Main Navigation Menus
var br;
if(navigator.appName == "Netscape" && navigator.appVersion.charAt(0)=="4")
	{br="N";}
else if(navigator.appName == "Microsoft Internet Explorer" && document.all != null)
	{br="IE";}
else if(navigator.appName == "Netscape" && document.getElementById != null && navigator.appVersion.charAt(0)=="5")
	{br="N5";}
else{br=null}


NS4 = (document.layers);
IE4 = (document.all);
ver4 = (NS4 || IE4);   
isMac = (navigator.appVersion.indexOf("Mac") != -1);
isMenu = (NS4 || (IE4 && !isMac ));     

function popUp(){return};
function popDown(){return};
function startIt(){return};

if (br){      
	if (document.images){
		// On images tabs store
		img1_on = new Image(97, 24);
		img1_on.src = "/Merchant2/graphics/en-US/mmui/gc/home_on.gif";

		// On images buttons bks
		bk_alpha_on = new Image(120, 24);
		bk_alpha_on.src = "/hdr/hdr_img/hdr_buttons/bk_alpha_on.gif";
	}
}
        
        
// A simple javascript to pop-up windows...
  
function openWindow(newURL, newWidth, newHeight, resize) {
  // Declare and initialize top and left variables
  var calcLeft = 100;
  var calcTop = 100;
        
  // Update properties if comp. browser
  if (parseInt(navigator.appVersion) >= 4){
  calcTop = screen.availHeight /2 - newHeight / 2;
  calcLeft = screen.availWidth / 2 - newWidth / 2;}

  // Open the new window using top and left properties
  window.open(newURL, 'remote', 'status=no,toolbar=no,menubar=no,location=no,scrollbars=no,width=' + newWidth + ',height=' + newHeight + ',left=' + calcLeft + ',top=' + calcTop + ',resizable=yes');
}   


        
// Functions to "hilite" images
function Act(imgName){ 
    if (document.images && (br !='N5')){
	    document[imgName].src = eval(imgName + '_on.src');
	}
}

function InAct(imgName) {
    if (document.images && (br !='N5')) document[imgName].src = eval(imgName + '_off.src') 
}


// functions that swap images & status bar
function imageOn(i){
	if(br){
		if (document.images){
			document.images[i].src = onImgArray[i].src;
			return (true);
		}
	}
}
function imageOff(i){
	if(br){
		if (document.images){
		document.images[i].src = offImgArray[i].src;
		return (true);
		}
	}
}
function setMsg(msg){
		window.status = msg;
		return (true);
}


// functions that check form entries on cust info
function InfoValidator(theForm){		
	if (theForm.ShipEmail.value == ""){
		alert("Please enter your email address.");
		theForm.ShipEmail.focus();
		return (false);
	}
	else{
	theForm.ShipEmail.value = theForm.ShipEmail.value.toLowerCase() ;
	}
				
	if (theForm.ShipFirstName.value == ""){
		alert("Please enter your first name.");
		theForm.ShipFirstName.focus();
		return (false);
	}
	else{
		theForm.ShipFirstName.value = capitalize(theForm.ShipFirstName.value);
	}
	
	if (theForm.ShipLastName.value == ""){
		alert("Please enter your last name.");
		theForm.ShipLastName.focus();
		return (false);
	}
	else{
		theForm.ShipLastName.value = capitalize(theForm.ShipLastName.value);
	}
	
	if (theForm.ShipPhone.value == ""){
		alert("Please enter your phone number.");
		theForm.ShipPhone.focus();
		return (false);
	}
	
	if (theForm.ShipAddress.value == ""){
		alert("Please enter your street address with any unit or apartment number.");
		theForm.ShipAddress.focus();
		return (false);
	}
	else{
		theForm.ShipAddress.value = findwords(theForm.ShipAddress.value);
	}
	
	if (theForm.ShipCity.value == ""){
		alert("Please enter your city.");
		theForm.ShipCity.focus();
		return (false);
	}
	
	if (theForm.ShipState_Select.options[theForm.ShipState_Select.selectedIndex].text == "Select US State"){	
	  if (theForm.ShipCountry.options[theForm.ShipCountry.selectedIndex].text == "United States"){
		alert("Please enter your state or country from the popup lists.");
		theForm.ShipState_Select.focus();
		return (false);
	  }
	}
	if (theForm.ShipZip.value == ""){
		alert("Please enter your zip code.");
		theForm.ShipZip.focus();
		return (false);
	}
	if (theForm.ShipEmail.value.length > 0){
		var checkOK = "@";
		var checkStr = theForm.ShipEmail.value;
		var allValid = false;
		for (i = 0;	 i < checkStr.length;  i++)
		{
			ch = checkStr.charAt(i);
			for (j = 0;	 j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
			{
				allValid = true;
				break;	
			}	  
		}
	}
	if (!allValid)
	{
		alert("The email address is in the wrong format! Use the name@company.com format in lower case.");
		theForm.ShipEmail.focus();
		return (false);
	}
	
	return (true);
}
 
// capitalize the first letter of a string and make the rest lowercase
function capitalize(astring){
	var tempstring = astring.substring(0,1).toUpperCase();
	tempstring += astring.substring(1);
	return (tempstring);
}
 
function findwords(theString){
	var firstposition = 0;
	var tempstring = "";
	theString.value = theString.value.toLowerCase();
	do{
		theString.value = capitalize(theString.value);
		firstposition = theString.value.indexOf(" ");
		if (firstposition != -1){
			tempstring += theString.value.substring(0,firstposition + 1);
			theString.value = theString.value.substring( firstposition + 1 );
		}
	}
	while ( theString.value.indexOf(" ") != -1 ) ;
	tempstring += capitalize( theString.value );
	theString.value=tempstring
	return(tempstring);
}

if(!orderform || orderform.closed){
	var orderform;
}
else{

}	

function OpenCertDetails(){
	thewindow = window.open('https://www.thawte.com/cgi/server/certdetails.exe?code=USGLAS12-1', 'anew', config='height=400,width=450,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,directories=no,status=yes');
}

function openOrderForm(){
	var tempURL ="/Merchant2/order_form.mv?";
	
	if(!orderform || orderform.closed){
		orderform = window.open(tempURL,"OrderForm","menubar,height=200,width=550");
		orderform.focus();
	}
	else{
		orderform.location=(tempURL);
		orderform.focus();
	}
}

if(!info || info.closed){
	var info;
}
else{

}	

function openCallout(activity){
	var tempURL ="/scripts/callout_fs.mv?Activity_Code=" + activity ;
	
	if(!info || info.closed){
		info = window.open(tempURL,"Info","menubar,height=400,width=495");
		info.focus();
	}
	else{
		info.location=(tempURL);
		info.focus();
	}
}


function openProductView(productcode){
	var tempURL ="/Merchant2/product_view.mv?Product_Code=" + productcode + "&Category_Code=" + categorycode;
	
	if(!info || info.closed){
		info = window.open(tempURL,"Info","menubar,height=400,width=495");
		info.focus();
	}
	else{
		info.location=(tempURL);
		info.focus();
	}
}

function openGlassForm(productcode, categorycode){
	var tempURL ="/Merchant2/order_form.mv?Product_Code=" + productcode+ "&Category_Code=" + categorycode;
	
	if(!info || info.closed){
		info = window.open(tempURL,"Info","menubar,height=400,width=495");
		info.focus();
	}
	else{
		info.location=(tempURL);
		info.focus();
	}
}

function openArtistGallery(pic_id){
	var tempURL ="/Merchant2/gallery_view.mv?Picture_ID=" + pic_id;
	
	if(!info || info.closed){
		info = window.open(tempURL,"Info","menubar,height=400,width=495");
		info.focus();
	}
	else{
		info.location=(tempURL);
		info.focus();
	}
}

function openSplashScreen(){
	var tempURL ="/Merchant2/splash_screen.mv";
	if(!info || info.closed){
		info = window.open(tempURL,"Info","menubar,height=400,width=495");
		info.focus();
	}
	else{
		info.location=(tempURL);
		info.focus();
	}
}

function openTellAFriend(code){
	if(code==""){
		var tempURL ="/Merchant2/tellafriend.mv?";
	}
	else{
		var tempURL ="/Merchant2/tellafriend.mv?Product_Code="+code;
	}
	
	if(!info || info.closed){
		info = window.open(tempURL,"Info","menubar,height=400,width=495");
		info.focus();
	}
	else{
		info.location=(tempURL);
		info.focus();
	}
}

function validateEmail(email){
	email.value=email.value.toLowerCase();
	if (email.value.length > 9){
		if((email.value.indexOf("@") > 1) && (email.value.indexOf(".") > 0)){
			return true;		
		}
		else{
			alert("Invalid email address format. Should be in the form of \'user@domain.com\'.");
			email.focus();
			return false;
		}
	}
	else{
		alert("Invalid email address format. Should be in the form of \'user@domain.com\'.");
		email.focus();
		return false;
	}
}

function updateState() {
	var vSelectedCountryIndex=document.customer_info.ShipCountry.selectedIndex;
	var vSelectedStateIndex=document.customer_info.ShipStateSelect.selectedIndex;
	if(!(document.customer_info.ShipCountry.options[vSelectedCountryIndex].text == "United States")) {
		if(!(document.customer_info.ShipStateSelect.options[vSelectedStateIndex].text=="Outside US")){
			document.customer_info.ShipStateSelect.options[0].selected = true;
		}
	}
	else if(document.customer_info.ShipStateSelect.options[vSelectedStateIndex].text=="Outside US"){
		document.customer_info.ShipState.value = ""
		alert("Please select an US State from the popup menu!");
	}
	var vSelectedBillCountryIndex=document.customer_info.BillCountry.selectedIndex;
	var vSelectedBillStateIndex=document.customer_info.BillStateSelect.selectedIndex;
	if(!(document.customer_info.BillCountry.options[vSelectedBillCountryIndex].text == "United States")) {
		if((document.customer_info.BillStateSelect.options[vSelectedBillStateIndex].text=="Outside US")){
			document.customer_info.BillStateSelect.options[0].selected = true;
		}
	}
	else if(document.customer_info.BillStateSelect.options[document.customer_info.BillStateSelect.selectedIndex].text=="Outside US"){
		document.customer_info.ShipState.value = "";
		alert("Please select an US State from the popup menu!");
	}
}

function updateCountry() {
	var vSelected=document.customer_info.ShipStateSelect.selectedIndex;
	if(!(document.customer_info.ShipStateSelect.options[vSelected].text == "Outside US")) {
		document.customer_info.ShipState.value = "";
		if(!(document.customer_info.ShipCountry.options[document.customer_info.ShipCountry.selectedIndex].text=="United States")){
			for(i=0;i<= document.customer_info.ShipCountry.length;i++){
				if(document.customer_info.ShipCountry.options[i].text=="United States"){
					document.customer_info.ShipCountry.options[i].selected = true;
					break;
				}
			}
		}
	}
	else{
		document.customer_info.ShipCountry.options[0].selected=true;
	}
	var vSelected=document.customer_info.BillStateSelect.selectedIndex;
	if(!(document.customer_info.BillStateSelect.options[vSelected].text == "Outside US")) {
		document.customer_info.BillState.value = "";
		if(!(document.customer_info.BillCountry.options[document.customer_info.BillCountry.selectedIndex].text=="United States")){
			document.customer_info.BillState.value = "";
			for(i=0;i<= document.customer_info.BillCountry.length;i++){
				if(document.customer_info.BillCountry.options[i].text=="United States"){
					document.customer_info.BillCountry.options[i].selected = true;
					break;
				}
			}
		}
	}
	else{
		document.customer_info.BillCountry.options[0].selected=true;
	}
}

function updateCustomerCountry() {
	var vSelected=document.customer_info.Customer_ShipStateSelect.selectedIndex;
	if(!(document.customer_info.Customer_ShipStateSelect.options[vSelected].text == "Outside US")) {
		document.customer_info.Customer_ShipState.value = "";
		if(!(document.customer_info.Customer_ShipCountry.options[document.customer_info.Customer_ShipCountry.selectedIndex].text=="United States")){
			for(i=0;i<= document.customer_info.Customer_ShipCountry.length;i++){
				if(document.customer_info.Customer_ShipCountry.options[i].text=="United States"){
					document.customer_info.Customer_ShipCountry.options[i].selected = true;
					break;
				}
			}
		}
	}
	else{
		document.customer_info.Customer_ShipCountry.options[0].selected=true;
	}
	var vSelected=document.customer_info.Customer_BillStateSelect.selectedIndex;
	if(!(document.customer_info.Customer_BillStateSelect.options[vSelected].text == "Outside US")) {
		document.customer_info.Customer_BillState.value = "";
		if(!(document.customer_info.Customer_BillCountry.options[document.customer_info.Customer_BillCountry.selectedIndex].text=="United States")){
			for(i=0;i<= document.customer_info.Customer_BillCountry.length;i++){
				if(document.customer_info.Customer_BillCountry.options[i].text=="United States"){
					document.customer_info.Customer_BillCountry.options[i].selected = true;
					break;
				}
			}
		}
	}
	else{
		document.customer_info.Customer_BillCountry.options[0].selected=true;
	}
}

function updateCustomerState() {
	var vSelectedCountryIndex=document.customer_info.Customer_ShipCountry.selectedIndex;
	var vSelectedStateIndex=document.customer_info.Customer_ShipStateSelect.selectedIndex;
	if(!(document.customer_info.Customer_ShipCountry.options[vSelectedCountryIndex].text == "United States")) {
		if(!(document.customer_info.Customer_ShipStateSelect.options[vSelectedStateIndex].text=="Outside US")){
			document.customer_info.Customer_ShipStateSelect.options[0].selected = true;
		}
	}
	else if((document.customer_info.Customer_ShipStateSelect.options[vSelectedStateIndex].text=="Outside US")){
		document.customer_info.Customer_BillState.value = "";
		alert("Please select an US State from the popup menu");
	}
	var vSelectedBillCountryIndex=document.customer_info.Customer_BillCountry.selectedIndex
	var vSelectedBillStateIndex=document.customer_info.Customer_BillStateSelect.selectedIndex
	if(!(document.customer_info.Customer_BillCountry.options[vSelectedBillCountryIndex].text == "United States")) {
		if(!(document.customer_info.Customer_BillStateSelect.options[vSelectedBillStateIndex].text=="Outside US")){
			document.customer_info.Customer_BillStateSelect.options[0].selected = true;
		}
	}
	else if(document.customer_info.Customer_BillStateSelect.options[vSelectedBillStateIndex].text=="Outside US"){
		document.customer_info.Customer_BillState.value = "";
		alert("Please select an US State from the popup menu");
	}
}
