
function openFullScreenWin( html, name, scroll) {
	var features;
	features = 'width='+ screen.width +',height='+ screen.height + ',top=0,left=0,toolbar=no,status=no,menubar=no,scrollbars='+scroll+',resizable=no';
	//alert('features:' + features);
	var n=window.open( html, name, features);
}

function PopResultsWindow(obj){

    var zip = obj.getElementById("zipcode").value;
    var radius= obj.getElementById("radius").value;
    
    openNewWindow('/search/?zipcode='+zip+'&radius='+radius+'&ZipSearchSubmit=1', 'newWin','width=600, height=400, top=0,left=0,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no');
}

function openNewWindow(theURL,winName,features) {
	var newWin;
	var locationString = '';
	if (newWin && ieX){
		locationString = locationString + newWin.location;
		if (locationString != ''){
			newWin.location.href = theURL;
		} else {
			newWin = window.open(theURL,winName,features);
		}
	} else {
		newWin = window.open(theURL,winName,features);
	}
	return newWin;
}

function roll(ele) {
	var img = ele.getElementsByTagName("img")[0];
	var src = img.src;
	img.src = (/_on/.test(src)) ? src.replace('_on', '_off') : src.replace('_off', '_on');
}

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 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){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}


function checkscript() {
    var theForm = document.forms[0];
   
    var aryReqFields= new Array(); 
    
   if(theForm.hidfrmType.value=='quoteform') {
    aryReqFields.push("fname", "lname",  "email", "phone", "product", "size", "quantity"); 
   }
   else{
      aryReqFields.push("name", "email", "phone"); 
   }
    
    var aryErrormsgs = new Array();
   if(theForm.hidfrmType.value=='quoteform') { 
    aryErrormsgs.push("First Name", "Last Name", "Valid Email Address", "Phone", "Product", "Size", "Quantity");
   }
   else{
        aryErrormsgs.push("Name", "Valid Email Address", "Phone");
    }    
    var theForm = document.forms[0]
    var alertText = "Unable to submit form required fields are missing or incorrect<br />";

    for(i=0; i<aryReqFields.length; i++){
            var error = false;
             if(theForm[aryReqFields[i]].value == ""){
            //errorText += aryErrormsgs[i] + "<br />"
            error=true;
            
            document.getElementById('lbl'+aryReqFields[i]).className="error";
          }
          else{
            if(aryReqFields[i] == "phone"){
                if(checkPhone(theForm[aryReqFields[i]].value)==false){
                error=true;
                document.getElementById('lbl'+aryReqFields[i]).className="error";
               } 
            }

            if(aryReqFields[i] == "email" && echeck(theForm[aryReqFields[i]].value)==false){
                error=true;
                document.getElementById('lbl'+aryReqFields[i]).className="error";
            }
            
            if(aryReqFields[i] == "quantity" && echeck(theForm[aryReqFields[i]].value)==false){
                if(isInteger(theForm[aryReqFields[i]].value)==false){
                error=true;
                document.getElementById('lbl'+aryReqFields[i]).className="error";
               } 
            }
            //reset class is no error or error has been corrected
            if(!error){document.getElementById('lbl'+aryReqFields[i]).className="label";}
          }
     }
     if(error){
            var errorObj = document.getElementById("errormessage");
            //alert(alertText);
            errorObj.innerHTML = alertText;
            return false;
        }else {
       return true; 
//        doPost('/asp/post.asp',theForm);
  //      location.href="/stage/contactus/thanks/"
        

  }
  
  }

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}



function onSubmitForm() {
    var formDOMObj = document.frmSend;
        if (formDOMObj.attach1.value == "" )
        {
            alert('Please press the browse button and pick a file') 
            return false;   
       } 
        else{   
            if (formDOMObj.attach1.value != ""  && (Right(formDOMObj.attach1.value,3) != "gif" && Right(formDOMObj.attach1.value,3) != "jpg" && Right(formDOMObj.attach1.value,3) != "doc" && Right(formDOMObj.attach1.value,3) != "xls" && Right(formDOMObj.attach1.value,3) != "pdf"))
            {
                alert('File Format not allowed (PDF, XLS, JPG, GIF , TIF ONLY)')  
                return false;
            }
            else
            {
                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 checkPhone(strPhone){
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- .";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;


s=stripCharsInBag(strPhone,phoneNumberDelimiters);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}


function showFlowers(){
    var myDiv = window.document.getElementById("flowersoverlay");
    myDiv.style.marginLeft = "0px";
}
function hideFlowers(){
    var myDiv = window.document.getElementById("flowersoverlay");
    myDiv.style.marginLeft="-1000px";
}
