﻿// ============================  POPUP Script  =================================
var PopUpState = 0;
var PopUpHEIGHT = 0;
var PopUpWIDTH = 0;
function ShowPOPUP(title,width,height){
	this.PopUpWIDTH = width;
	this.PopUpHEIGHT = height;
	
	var PopUp = document.getElementById("PopUp");
	PopUp.style.width = width + 'px';
	// header
	var PopUpHeader = document.getElementById("PopUpHeader").getElementsByTagName("*");
	PopUpHeader[0].style.width = (width - 76 ) + 'px';   // middle
	PopUpHeader[1].innerHTML = title;  // set title
	PopUpHeader[2].style.marginLeft = (width - 100 ) + 'px';   // close button
	
	
	// Body
	var PopUpBody = document.getElementById("PopUpBody").getElementsByTagName("*");
	PopUpBody[0].style.width = (width - 38 ) + 'px';    // middle
	//PopUpBody[1].style.width = (width - ( 76 )) + 'px';    //contact
	//PopUpBody[2].style.width = (width - ( 76 + 38 )) + 'px';    //Div callback control,update panel
	
	// Footer
	var PopUpFooter = document.getElementById("PopUpFooter").getElementsByTagName("*");
	PopUpFooter[0].style.width = (width - 76 ) + 'px';    // middle
	
	
	var CoverUpdiv = document.getElementById("CoverUpdiv");
	
	CoverUpdiv.style.width = document.documentElement.clientWidth + 'px';
	CoverUpdiv.style.height = (document.documentElement.clientHeight + (document.body.scrollHeight - document.documentElement.clientHeight )) + 'px';
	CoverUpdiv.style.display = 'block';
	
	PopUp.style.top = (parseInt(document.documentElement.clientHeight / 2) - parseInt(height/2)) + 'px';
	PopUp.style.left = (parseInt(document.documentElement.clientWidth / 2) - parseInt(width/2)) + 'px';
	PopUp.style.display='block';
	
	this.PopUpState = 1;
	
	return false;
}
function RearrangePopUp(){
	if(this.PopUpState == 1){
		// arrange cover up div
        var CoverUpdiv = document.getElementById("CoverUpdiv");
	    CoverUpdiv.style.width = document.documentElement.clientWidth + 'px';
	    CoverUpdiv.style.height = (document.documentElement.clientHeight + (document.body.scrollHeight - document.documentElement.clientHeight )) + 'px';
	    
	    // arrange popup to center of screen
	    var PopUp = document.getElementById("PopUp");
	    PopUp.style.top = (parseInt(document.documentElement.clientHeight / 2) - parseInt(this.PopUpHEIGHT/2)) + 'px';
	    PopUp.style.left = (parseInt(document.documentElement.clientWidth / 2) - parseInt(this.PopUpWIDTH/2)) + 'px';
    }
}

function ClosePOPUP(){
	var CoverUpdiv = document.getElementById("CoverUpdiv");
	CoverUpdiv.style.display = 'none';
	
	var PopUp = document.getElementById("PopUp");
	PopUp.style.display='none';
	
	this.PopUpState = 0;
	return false;
}

	// find position of object
function findPosX(obj)
{
	var curleft = 0;
	if(obj.offsetParent)
		while(1) 
		{
			curleft += obj.offsetLeft;
			if(!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if(obj.offsetParent)
		while(1)
		{
			curtop += obj.offsetTop;
			if(!obj.offsetParent)
				break;
			obj = obj.offsetParent;
		}
	else if(obj.y)
			curtop += obj.y;
	return curtop;
}

function ScrollTop(){
    if(document.documentElement.scrollTop)
        document.documentElement.scrollTop = '0px';
    else
        document.body.scrollTop = '0px';
}
/*==============  For Search =================*/
function GoForSearch(){
    var txt = document.getElementById("txtSearch");
    if(!ValidateString(txt)){
        alert("please enter text for search");
        return false;
    }
    location.href = "search.aspx?q=" + txt.value + "&l=0";
}

function OnEnterGoForSearch(e){
    var characterCode 
    if(e && e.which){ 
        characterCode = e.which ;
    }
    else{
        e = event;
        characterCode = e.keyCode ;
    }

    if(characterCode == 13){ 
        GoForSearch();
    return false
    }
    else{
        return true
    }

}

// PreLoadsImages();
var imgurl = "";
var arrsrc = Array();
    arrsrc[0] = "images/logo.jpg";
    arrsrc[1] = "images/login.jpg";
    arrsrc[2] = "images/contact-us.jpg";
    arrsrc[3] = "images/sub-menu-bg.jpg";
    arrsrc[4] = "images/menu-hover-bg.jpg";
    arrsrc[5] = "images/menu-seperator.jpg";
    arrsrc[6] = "images/partners.jpg";
    arrsrc[7] = "images/products.jpg";
    arrsrc[8] = "images/btn_more.jpg";
    arrsrc[9] = "images/btn_move_hover.jpg";
    arrsrc[10] = "images/technology.jpg";
    arrsrc[11] = "images/why-us.jpg"
    arrsrc[12] = "images/salesforce.jpg";
    arrsrc[13] = "images/request-demo.jpg";
    arrsrc[14] = "images/request-demo-o.jpg";
    arrsrc[15] = "images/web2.jpg";
    arrsrc[16] = "images/web2-o.jpg";
    arrsrc[17] = "images/manage_services.jpg";
    arrsrc[18] = "images/manage_services-o.jpg";
    arrsrc[19] = "images/cloud3_computing.jpg";
    arrsrc[20] = "images/cloud3_computing-o.jpg";
    
var imgLoaded = Array();  
var arrimages = Array(); 
var TimeO ;
var NoOfRepetation = 0;
var ProgressBar11MinValue = 0;
function PreLoadsImages(){
    // cover div
    height = screen.height + 110;
    width = document.documentElement.clientWidth - 18;
    // pregress div
    progressWidth = 150;
    progressHeight = 100;
    progressTop = 0;//parseInt(document.documentElement.clientHeight / 2) - parseInt(progressHeight/2);
    progressLeft = parseInt(document.documentElement.clientWidth / 2) - parseInt(progressWidth/2); 
    //<div id='div_Initialized' style='position:absolute;z-index:16;height:"+progressHeight+"px;width:"+progressWidth+"px;top:"+progressTop+"px;left:"+progressLeft+"px;border:1px solid red;'></div>
    var div = "<div id='div_preloding' style='position:absolute;display:block;filter: alpha(opacity=50);opacity: 0.5;padding:0px;z-index:15; height:"+height+"px; width:"+width+"px;background-color:#e1e1e1;'><div id='div_Initialized' style='position:absolute;top:0px;z-index:16;height:"+progressHeight+"px;width:"+progressWidth+"px;top:"+progressTop+"px;left:"+progressLeft+"px;border:0px solid red;'>Initializing....</div></div>";
    document.write(div);
    Load_images();
}

function Load_images(){
    
    for(i=0; i<arrsrc.length;i++){ // initialize image array 
        arrimages[i] = new Image();
        arrimages[i].src = arrsrc[i];
        imgLoaded[i] = false;
    }
    // set incremant value of progress bar
    this.ProgressBar11MinValue = parseInt( 60 /arrsrc.length); // progress bar width = 60
    //clearTimeout(this.TimeO); 
    this.TimeO = setTimeout(CheckLoad,100);
    
}

function CheckLoad(){
    var cnt1 = 0;
    for(i=0; i<arrsrc.length;i++){ // check for image loded
        if(arrimages[i].height > 0){
            if(imgLoaded[i] == false){
                imgLoaded[i] = true;
                //document.getElementById("ProgressBar11").style.width = (parseInt(document.getElementById("ProgressBar11").style.width.replace(/px/,'')) + this.ProgressBar11MinValue) + 'px';
                //alert('d')
            }
            cnt1 += 1;
        }else
            cnt1 -= 1;
    }   
    if(cnt1 == arrsrc.length){
        document.body.removeChild(document.getElementById("div_preloding"));
        clearTimeout(this.TimeO);
    }else{
        this.TimeO = setTimeout(CheckLoad,100); 
    }
    // if recursion is more the 100 then break
    this.NoOfRepetation +=1;
    if(this.NoOfRepetation > 40 ){
        document.body.removeChild(document.getElementById("div_preloding"));
        clearTimeout(this.TimeO);
    }
}

function ReArrangePreloding(){
    if(document.getElementById("div_preloding")){
        div = document.getElementById("div_preloding");
        div.style.width = (document.documentElement.clientWidth ) + 'px';
        
        progressDiv = document.getElementById("div_Initialized");
        //progressDiv.style.top = parseInt(document.documentElement.clientHeight / 2) - parseInt(progressDiv.style.height.replace(/px/,'')/2) + 'px';
        progressDiv.style.left = (parseInt(document.documentElement.clientWidth / 2) - parseInt(progressDiv.style.width.replace(/px/,'')/2)) + 'px'; 
    }
}
//  ==================  Validation Script ===================

function Trim(str) {
	return str.replace(/^\s+|\s+$/g,"");
}

function ValidateDate(control){
	var x = Trim(control.value);
	var filter  = /^([0-9]{4}-[0-9]{2}-[0-9]{2})$/;
	if (!filter.test(x)){
	 	return false;
	}else
		return true;
}

function ValidateString(control){
	var x = Trim(control.value);
	if (x.length == 0){
	 	return false;
	}else
		return true;
}

function validateEmail(control,msg)
{
	var x = Trim(control.value);
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(x)) 
		 	return false;
	else
		return true;
}