/**
 * Opens a new window
**/

var curPopupWindow = null;

function openWindow(url, winName, width, height, center) {
	
   var xposition = 50; // Postions the window vertically in px
   var yposition = 50; // Postions the window horizontally in px


   if ((parseInt(navigator.appVersion) >= 4 ) && (center)){
       xposition = (screen.width - 800) / 2;
       yposition = (screen.height - 600) / 2;
   } 

   // Features to specify for a new window
   args = "width=" + width + ","
   + "height=" + height + ","
   + "location=0,"
   + "menubar=0,"
   + "resizable=1,"
   + "scrollbars=1,"
   + "status=0,"
   + "titlebar=0,"
   + "toolbar=0,"
   + "hotkeys=0,"
   + "screenx=" + xposition + ","  //NN Only
   + "screeny=" + yposition + ","  //NN Only
   + "left=" + xposition + ","     //IE Only
   + "top=" + yposition;           //IE Only

   // Performs the opening of the window.
   	if (curPopupWindow != null) {
	   
		if (!curPopupWindow.closed) {
			curPopupWindow.close();
		}
		curPopupWindow = null;
	}
	curPopupWindow = window.open(url, winName, args, false);
	curPopupWindow.focus();

}

/**
 * Verify that an email addres is valid
 * Written by Paolo Wales (paolo@taize.fr)
**/

function isValidEmail(emailad) {

   var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
   var check=/@[\w\-]+\./;
   var checkend=/\.[a-zA-Z]{2,3}$/;

   if(((emailad.search(exclude) != -1) ||
       (emailad.search(check)) == -1) ||
       (emailad.search(checkend) == -1)){
      return false;
   } else {
      return true;
   }
}

/**
 * Validate phone number for signup
**/

function isValidPhoneNumber(num) {
    var digits = 0;
    if (num == null) return false;
    for( i=0; i<num.length; i++ ){
    	var c = num.charCodeAt(i);  
    	//convert the i-th character to ascii code value
    	if( (c>=48) && (c<=57) ) digits++;
    }	
    return (digits >= 10);
}

/**
 * Image swaping (mouseover) for the Web site
**/

function swapImage(daImage, daSrc){
var objStr, obj;
	if(document.images){
		if (typeof(daImage) == 'string') {
			objStr = 'document.' + daImage;
			obj = eval(objStr);
			obj.src = daSrc;
		} else if ((typeof(daImage) == 'object') && daImage && daImage.src) {
			daImage.src = daSrc;
		}
	}
}

/** 
 * Validate document for signup
**/

function validateLocation() {
	if (document.forms[0].country.value == 0)
		alert("You must select a location");
}

/** 
 * Get cookie for login
**/

function getCookieValue(cookieName) {
  var c = document.cookie;
  var idx = c.indexOf('login=');
  if ( idx == -1) return "";
  idx += 'login='.length;
  var end = c.indexOf(';',idx);
  if ( end == -1) end = c.length;
  return c.substring(idx,end);
}

/** 

 * Preload Images 
**/

function preloadImages() {
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

/**
 * Close tour window and bring up signup screen(s)
**/

function switchWindows(url) {
   top.opener.location.href=url;	
   top.close();
}

/**
 * Validate partner forms.
**/

function partnerValidation() {
   if (document.partnerForm.first_name.value == 0) {
      alert("You must enter a First Name");
      return false;
   } else if (document.partnerForm.last_name.value == 0) {
      alert("You must enter a Last Name");
      return false;
   } else if (document.partnerForm.phone.value == 0) {
      alert("You must enter a Phone Number");
      return false;
   } else if (document.partnerForm.email.value == 0) {
      alert("You must enter an Email Address");
      return false;
   } else if (document.partnerForm.company.value == 0) {
      alert("You must enter a Company Name");
      return false;
   } else if (document.partnerForm.street.value == 0) {
      alert("You must enter a Street Address");
      return false;
   } else if (document.partnerForm.city.value == 0) {
      alert("You must enter a City");
      return false;
   } else if (document.partnerForm.state.selectedIndex == "0") {
      alert("You must enter a State");
      return false;
   } else if (document.partnerForm.zip.value == 0) {
      alert("You must enter a Zip/Postal Code");
      return false;
   } else if (document.partnerForm.country.selectedIndex == "0") {
      alert("You must enter a Country Code");
      return false;
   } else {
     return true;
   }
}

/**
 * Validate billing inquiry feilds
**/

function billingValidation() {
   if (document.webtocase.first_name.value == 0) {
      alert("You must enter a Name");
      return false;
   } else if (document.webtocase.company.value == 0) {
      alert("You must enter a Company Name");
      return false;
   } else if (document.webtocase.email.value == 0) {
      alert("You must enter an Email Address");
      return false;
   } else if (document.webtocase.subject.value == 0) {
      alert("You must enter a Subject");
      return false;
   } else if (document.webtocase.description.value == 0) {
      alert("You must enter a Question");
      return false;
   } else {
     return true;
   }
}

/* 
 * Used to get query string arguments before user
 * has a chance to alter them on the billing inqury form.
 * (billing_inquiry.jsp)
 */

function winInit() {
	var args = getArgs();

	//show email field if not supplied -
	//set value to empty string if null
	var eml = args["eml"];
	document.webtocase.email.value = (eml != null ? eml : "");

	//show name field if not supplied -
	//set value to empty string if null
	var nm = args["nm"];
	document.webtocase.first_name.value = (nm != null ? nm : "");

	//show company field if not supplied -
	//set value to empty string if null
	var co = args["co"];
	document.webtocase.company.value  = (co != null ? co : "");
}

/* parses name=value argument pairs from
 * the query string of the URL. It stores the pairs in 
 * properties of an object and returns that object from the
 * billing inqury form. (billing_inquiry.jsp)
 */

function getArgs() {
    var args = new Object();

    // Get query string.
    var query = location.search.substring(1);  

    // Break at ampersand.
    var pairs = query.split("&"); 

       for (var i = 0; i < pairs.length; i++) {
       // Look for "name=value"
       var pos = pairs[i].indexOf('=');

       // If not found, skip.
       if (pos == -1) continue; 
	   		
       // Extract the name.              
       var argname = pairs[i].substring(0,pos);  
			
       // Extract the value.
       var value = pairs[i].substring(pos+1);
			
       // Store as a property. 
       args[argname] = unescape(value);       
     }
   return args;
}

function OpenWTS(){
	NotIE=true;
	if (navigator.appName == "Microsoft Internet Explorer" && !navigator.appVersion < "6.0")
	 {NotIE=false;}
	if (NotIE) {alert("Microsoft Internet Explorer 6.0 or higer is required for the applicaion.");return false;}
	window.open('http://www.worldtradesystems.net/MainFrame.jsp','WTS','height=710, width=1020, left=0, top=0,resizable=1, scrollbars=0, status=0, menubar=0, toolbar=0');
		}

