﻿ function setImagesize()
    {
        var imgwidth=document.getElementById("chkimgsize").width;
        var imgheight=document.getElementById("chkimgsize").height;
	    if (imgheight > 350 && imgwidth < 500)
	    {
	    document.getElementById("chkimgsize").width=imgwidth * .35;
	    document.getElementById("chkimgsize").height=imgheight * .35;
    	
	    }
	    else if (imgwidth > 750)
	    {
	    document.getElementById("chkimgsize").width=imgwidth * .75;
	    document.getElementById("chkimgsize").height=imgheight * .75;
	    }
	    else
	    {
	    document.getElementById("chkimgsize").width=imgwidth;
	    }
    }
    
    function popUp(URL)
    {
        day = new Date();
        id = day.getTime();
        eval("page" + id + " = window.open(URL, 'printOffer', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=850,height=600,left = 120,top = 160');");
    }
    function CheckValidEmail()
    {
        var objMail = document.getElementById('txtReferAFriend').value;
        if (objMail=="")
        {
            alert('Enter Email id');
            return false ;
        }
        var arryofstring=new Array(); 
        arryofstring=objMail.split(';'); 
          for(var i=0;i<arryofstring.length;i++)
          {
            if(arryofstring[i] != "" && arryofstring[i] != null)
            {  
                if(!(isValidEmail(arryofstring[i])))
                {
                    alert('Enter Valid Email id');
                    return false ;
                }
               
            }
         }
        return true;
    }
    
    function popup(mylink, windowname)
    {
        if (! window.focus)
            return true;
        var href;
        if (typeof(mylink) == 'string')
           href=mylink;
        else
           href=mylink.href;
        
        window.open(href, windowname, 'height=800px,width=400px, top=300,left=300,titlebar=no,toolbar=no,menubar=no,scrollbar=yes,resizable=yes,location=no,directories=no,minimize=no,maximize=no');
        return false;
    }
    function hideModalPopup()
    {
      var modalpopup = $find('programmaticModalPopupBehavior'); 
      modalpopup.hide(); 
      document.getElementById('txtReferAFriend').value="Enter Friend's Email";
      document.getElementById('txtReferAFriend').style.color='gray';
    }
    function  isValidEmail(emailID)  
    {
	    var expIsSpecialChar=/[^a-zA-Z0-9_@.]/   			
	    var expFirstCharOfEmail = /[^0-9a-zA-Z]/
	    if(expIsSpecialChar.test(emailID))
	    {
	        return false;
        }

	    /// Number of '@' chars present in input string.
	    var  numAtChars;
	    /// The part of input address before the '@' character.
	    var  userNameIn;
	    /// The part of input address after the '@' character.
	    var  domainNameIn;
	    /// Holds the fields of the entered address, delimitted by '@' chars.
	    var  addressFields = new Array();
	    /// Divide the input email address into fields.
	    ///  Note that the array "addressFields" will have one more element
	    ///  than the number of '@' signs in the input string.
	    /// IE4 handles this OK with '@' as last character but NS4,4.5 and Opera 3.5 don't.
	    addressFields = emailID.split('@');
	    numAtChars = addressFields.length - 1;
	    // Has to be added in the email validation 
	    // This checks the dot at the last of the user name 
	    // Also  this checks for the first entered character 
	    // of email is a charactre or not
	    //============================
	    var dotPosition;
	    dotPosition = addressFields[0].length-1;			
	    if(addressFields[0].lastIndexOf(".") == dotPosition) 
		    return false;	
	    if(expFirstCharOfEmail.test(addressFields[0].substring(0,1)))	
		    return false;	
	    //===============================
	    if (emailID == "") 	 		//  is EMPTY
    	    return false;
	    else if (numAtChars  ==  0) //  contains no '@' character 
	        return false;
	    else if (numAtChars  >  1)	//  more than one '@' characters 
	        return false;
	    else if (addressFields[0] == "")	// has no Username before the '@' character 
            return false;
	    else if (addressFields[1] == "")	// has no Domain Name after the '@' character
    	    return false;
	    else
	    {
		    userNameIn   = addressFields[0];
		    domainNameIn = addressFields[1];
		    if (userNameIn.indexOf( " " ) != -1)	// has one or more Spaces in the Username before the '@'  
			    return false;
		    else if (domainNameIn.indexOf( " " ) != -1) 	// has one or more Spaces in the Domain Name after the '@' character
    		    return false;
    //		else if (isStandardDomain( domainNameIn ) == false) 	//does not end with a '.com' style domain or two letter country code domain
    //			return false;
	    }
	    return true;           
    }

 