// Picture Brite JavaScript

//This function validates email address
function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid email address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid email address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			alert("Invalid email address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
			alert("Invalid email address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			alert("Invalid email address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
			alert("Invalid email address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
			alert("Invalid email address")
		    return false
		 }

 		 return true					
	}

function ValidateBillEmail(emailID){
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID");
		emailID.focus();
		emailID.select();
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.focus();
		emailID.select();
		return false
	}
	document.checkoutForm.submit();
 }

function ValidateEmail(emailID){
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email Address")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.focus()
		return false
	}
	return ValidateBillEmail(document.checkoutForm.billEmail);
 }

//This function validates the ship phone
	// Declaring required variables
	var digits = "0123456789";
	// non-digit characters which are allowed in phone numbers
	var phoneNumberDelimiters = "()- ";
	// characters which are allowed in international phone numbers
	// (a leading + is OK)
	var validWorldPhoneChars = phoneNumberDelimiters + "+";
	// Minimum no of digits in an international phone no.
	var minDigitsInIPhoneNumber = 10;
	
function loadPBFrame(pbURL){
	document.mainFrame.location = pbURL;
}

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}
function validateBillPhoneNumber(Phone){
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please Enter your Phone Number")
		Phone.select();
		Phone.focus();
		return false
	}
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please Enter a Valid Phone Number, your Phone Number must only contain numbers...no dashes or dots please...");
		Phone.select();
		Phone.focus();
		return false
	}
	return ValidateEmail(document.checkoutForm.shipEmail);
 }

function validateShipPhoneNumber(Phone){
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please Enter your Phone Number")
		Phone.focus()
		return false
	}
	if (checkInternationalPhone(Phone.value)==false){
			alert("Please Enter a Valid Phone Number, your Phone Number must only contain numbers...no dashes or dots please...");
		Phone.select()
		Phone.focus()
		return false
	}
	return validateBillPhoneNumber(document.checkoutForm.billPhone);
 }


//This function write the date
function writeDate(){
	var months=new Array(13);
	months[1]="January";
	months[2]="February";
	months[3]="March";
	months[4]="April";
	months[5]="May";
	months[6]="June";
	months[7]="July";
	months[8]="August";
	months[9]="September";
	months[10]="October";
	months[11]="November";
	months[12]="December";
	var time=new Date();
	var lmonth=months[time.getMonth() + 1];
	var date=time.getDate();
	var year=time.getYear();
	if (year < 2000)    // Y2K Fix
	year = year + 1900; //
	document.write(lmonth + " ");
	document.write(date + ", " + year);
}
	

// Text Input Field Highlight
function setBgImage(element,imageFile) {
	if (navigator.appVersion.indexOf("Win")!=-1){
  element.style.backgroundImage="url("+imageFile+")";
  element.style.color="#354D73";}
}

// Text Input Field Normal
function setBgImageOver(element,imageFile) {
if (navigator.appVersion.indexOf("Win")!=-1){	
  element.style.backgroundImage="url("+imageFile+")";
  element.style.color="#FFFFFF";}
}

function expand(listID) {
        if (listID.style.display=="none") {
                listID.style.display="";
        }
        else {
                listID.style.display="none";
        }
        window.event.cancelBubble=true;
}
function contract(listID) {
        if (listID.style.display=="show") {
                listID.style.display="";
        }
        else {
                listID.style.display="none";
        }
        window.event.cancelBubble=true;
}
function mouseover(el) {
  el.className = "leftMainNavHover";
}

function mouseout(el) {
  el.className = "leftMainNav";
}

function mousedown(el) {
  el.className = "pressed";
}

function mouseup(el) {
  el.className = "leftMainNavHover";
}
// Button Rollovers
function changeColor(color){
  var el=event.srcElement;
  if (el.tagName=="INPUT"&&(el.type=="button"||el.type=="submit"||el.type=="reset"))
  event.srcElement.style.backgroundColor=color;
}
function launchwin(winurl,winname,winfeatures)
{
	//This launches a new window and then
	//focuses it if window.focus() is supported.
	newwin = window.open(winurl,winname,winfeatures);
	if(parseInt(navigator.appVersion) >= 4)
	{
		//delay a bit here because IE4 encounters errors
		//when trying to focus a recently opened window
 		setTimeout('newwin.focus();',250);
	}
}
function launchFullWin(winurl,winname)
{
	//This launches a new window and then
	//focuses it if window.focus() is supported.
  	var winl = 0;//screen.width / 2;
  	var wint = 0;//screen.height / 2;
	newwin = window.open(winurl,winname,'scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes,top=' + wint + ',left=' + winl + ',width=' + screen.width + ',height=' + screen.weight);
	if(parseInt(navigator.appVersion) >= 4)
	{
		//delay a bit here because IE4 encounters errors
		//when trying to focus a recently opened window
 		setTimeout('newwin.focus();',250);
	}
}
function launchCenteredWin(url, name, width, height, otherfeatures)
{
  var str = "height=" + height + ",innerHeight=" + height;
  str += ",width=" + width + ",innerWidth=" + width;
  if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 10;

    var xc = (aw - width) / 2;
    var yc = (ah - height) / 2;

    str += ",left=" + xc + ",screenX=" + xc;
    str += ",top=" + yc + ",screenY=" + yc;
  }
  newwin = window.open(url, name, str + ',' + otherfeatures);
  if(parseInt(navigator.appVersion) >= 4)
  {
	//delay a bit here because IE4 encounters errors
	//when trying to focus a recently opened window
 	setTimeout('newwin.focus();',250);
  }
}
function launchNewsWin(winurl,winname)
{
	//This launches a new window and then
	//focuses it if window.focus() is supported.
	newwin = window.open(winurl,winname,'scrollbars=yes,resizable=yes,width=800,height=600');
	if(parseInt(navigator.appVersion) >= 4)
	{
		//delay a bit here because IE4 encounters errors
		//when trying to focus a recently opened window
 		setTimeout('newwin.focus();',250);
	}
}
function targetProduct(winurl)
{
	parent.mainFrame.location.href = winurl;
}

//Script:     Print Current Window From A Link
//Function:   Opens printer dialogue to print current page
//Browsers:   Version 4 and later (others degrade gracefully)
//<a href="javascript:printWindow()">Print This Page</a>
function printWindow(){
   bV = parseInt(navigator.appVersion)
   if (bV >= 4) window.print()
}
//Checks if the value is an integer
//onBlur="validateInteger(this)'"
function validateInteger(x) {
  if (isNaN(x.value))
  {
  x.focus();
  x.select();
  alert("\"" + x.value + "\"" + " is not a number, please re-enter a valid number.");
  return false;
  }
  else
  return true;
}

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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function maximizeWin(winName,splashURL,replaceURL,initialLoad)
{
  if(!replaceURL)
  {
    replaceURL= (GetCookie('flash') == 'yes') ? 'flash-index.htm' : 'html-index.htm';
  }

  isFullScreen = (GetCookie('fullscreen') == 'yes');
  if(isFullScreen && !initialLoad) {
    SetCookie('fullscreen','no');
    window.open(replaceURL,'');
    top.location.replace(splashURL);
    top.close();
  } else {
    SetCookie('fullscreen','yes');
    if(document.layers) {
      // Netscape 4.x
      self.name=winName;
      launchFullWin(replaceURL,winName);
    } else if(document.all) {
      // Internet Explorer
      launchFullWin(replaceURL,winName);
      top.location.replace(splashURL);
    } else if(document.getElementById) {
      // Netscape 6.x
      self.moveTo(0,0);
      self.resizeTo(screen.availWidth, screen.availHeight);
      self.personalbar.visible=false;
      self.statusbar.visible=false;
      self.toolbar.visible=false;
      self.menubar.visible=false;
    }
  }
}

//  End -->
