function isValidPhoneNumber(val)
{
    if(val.length<=9)
    {
        alert("Invalid phone number.\nPhone Number Must Be Entered As. 00971 50 1234567")
        return false
    }
			
    return true
}
	
function ConvertToDigits(val)
{

    var a = ""
    for(i=0;i<val.length;i++)
    {
				
				
				
        if(!isNaN(val.substring(i,i+1)))
        {
            if(val.substring(i,i+1)!=" " )
            {
                a+=val.substring(i,i+1);
            }
        }
				
    }
		 
    val=a;
		 
    ln=val.length;
    for(i=0;i<ln;i++)
    {
        if(val.substring(0,1)==0)
        {
            val=val.substring(1,ln);
        }
    }
		 
    return val;
}
	
	

function ReArrangePhoneNumber(PhoneNumber)
{

    var PhoneNumber =ConvertToDigits(PhoneNumber);

    var ph=PhoneNumber;
    ln=PhoneNumber.length;
	
    for(i=0;i<ln;i++)
    {
        if(PhoneNumber.substring(0,1)==0)
        {
            PhoneNumber=PhoneNumber.substring(1,ln);
        }
    }

    if(PhoneNumber!="")
    {
        ph="00"+PhoneNumber;
    }
		
		
		
		
		
		
		
    return ph;
}

function getCountry(value) 
{ 
	
    var url = 'getCountryDropBox.php';
    var myAjax = new Ajax.Request
    (
        url,
        {
            method: "post",
            parameters : "CountryId="+value,
            onSuccess: function transResult (response)
            {
                document.getElementById('Country').innerHTML=response.responseText;
            },
            onFailure: function transResult (response)
            {
                alert ('Failure'+response.responseText);
            }
        }
        );
    return false;
} 
	
function getCity(countryid,cityid,divId,fieldName)
{
		

    var url = 'getCityDropBox.php';
    //var divId='City';

    var myAjax = new Ajax.Request
    (
        url,
        {
            method: "post",
            parameters : "CountryId="+countryid+"&CityId="+cityid+"&fieldName="+fieldName,
					 
            onSuccess: function transResult (response)
            {
                document.getElementById(divId).innerHTML=response.responseText;
            },
            onFailure: function transResult (response)
            {
                alert ('Failure'+response.responseText);
            }
        }
        );
    return false;
		
}




	
function CheckEmail(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 CheckMobileNumber(str)
{
    if(str.length<9)
    {
        alert("Invalid Mobile number")
        return false
				
    }
    return true
}

function CheckLandLineNumber(str)
{
    if(str.length<7)
    {
        alert("Invalid number")
				
        return false
				
    }
    return true;
}
	
function toUpper(val) {
    var pattern = /(\S)(\S*)/; // a letter, and then one, none or more letters

	
    if(val.length==0)
    {
        return ""
    }
    var a = val.split(/\s+/g); // split the sentence into an array of words


    for (i = 0 ; i < a.length ; i ++ ) {
        var parts = a[i].match(pattern); // just a temp variable to store the fragments in.

        var firstLetter = parts[1].toUpperCase();
        var restOfWord = parts[2].toLowerCase();

        a[i] = firstLetter + restOfWord; // re-assign it back to the array and move on
    }
    
    a = a.join(' '); // join it back together
    return a;
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


function getNumber(num)
{
	
    var a = ""

    for(i=0;i<num.length;i++)
    {
        if(!isNaN(num.substring(i,i+1)))
        {
            a+=num.substring(i,i+1);
        }
			
    }
	 
    return a;
}
	
function ShowHide(ctrlName,hide)
{
		
    if(hide==1)
    {
				
        document.getElementById(ctrlName).style.display='none';

    }
    else
    {
        document.getElementById(ctrlName).style.display='block';
    }
			
}
	
	
function validateContactUs()
{
    if(document.frmContactUs.strName.value=="")
    {
        alert("Please enter your Name");
        document.frmContactUs.strName.focus();
        return false
    }
		
    if(document.frmContactUs.account.value=="")
    {
        alert("Please enter your Company Name");
        document.frmContactUs.account.focus();
        return false
    }
		
    if(document.frmContactUs.job_title.value=="")
    {
        alert("Please enter your Job Title");
        document.frmContactUs.job_title.focus();
        return false
    }
	
    if(document.frmContactUs.Tel1.value=="")
    {
        alert("Please enter your Telephone No.");
        document.frmContactUs.Tel1.focus();
        return false
    }

    if(document.frmContactUs.Mob1.value=="")
    {
        alert("Please enter your Mobile No.");
        document.frmContactUs.Mob1.focus();
        return false
    }
		
    if(document.frmContactUs.Email1.value=="")
    {
        alert("Please enter your Email Adress");
        document.frmContactUs.Email1.focus();
        return false
    }
		
    if(CheckEmail(document.frmContactUs.Email1.value)==false)
    {
        alert("Please enter valid Email");
        document.frmContactUs.Email1.focus();
        return false
    }
    if(document.frmContactUs.City1.value=="")
    {
        alert("Please enter your City");
        document.frmContactUs.City1.focus();
        return false
    }

    if(document.frmContactUs.Country1.selectedIndex==0)
    {
        alert("Please enter your Country");
        document.frmContactUs.Country1.focus();
        return false
    }

    if(document.frmContactUs.comments.value=="")
    {
        alert("Please enter your Coments/Queries");
        document.frmContactUs.comments.focus();
        return false
    }

    return true;
}

function openWindow(strUrl,width,height){
    mywindow = window.open(strUrl, "print","width=" + width + ",location=no,height="+height);
    //mywindow = window.open(strUrl, "print","width=400,location=no,height=400");
    mywindow.moveTo(0,0);
}