function CallCss() {
    var sty = '<link href="StyleSheet.css" rel="stylesheet" type="text/css" />' +
              '<link href="Include/featuredcontentglider.css" rel="stylesheet" type="text/css" />' +
              '<link href="Thickbox/thickbox.css" rel="stylesheet" type="text/css" />' +
              '<link href="StyleSheet_new.css" rel="stylesheet" type="text/css" />' +
              '';

    document.write(sty);
}
function CallCssLandingPage() {
    var sty = '<link href="LandingPage.css" rel="stylesheet" type="text/css" />';
    document.write(sty);
}

function goUrl(n) {
    if (n == '1') {
        window.location = 'index_.aspx';   
    }
}

function myPostBack(status,argName,argVal) 
{
    if (arguments[3] == true) {
        var validationGroup = "";
        if(arguments[4]){
            validationGroup = arguments[4];
        }
        if (typeof(Page_ClientValidate) == 'function') {
            Page_ClientValidate(validationGroup);
        }
    }

    var theForm = document.forms[0];
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        var hdnStatus = document.getElementById("status");
        if(hdnStatus)hdnStatus.value = status;
        var hdnArgument = document.getElementById(argName);
        if(hdnArgument)hdnArgument.value = argVal;
        theForm.submit();
    }
}

function HaveChecked(idcheckitem) {
    var res = false;
    var isChecked = jQuery("input:checkbox[id*=" + idcheckitem + "]:checked").length;
    if (isChecked > 0) res = true;

    if (res != true) {
        alert("You currently have no data selected.");
    }

    return res;
}

function confirmDelete(idcheckitem) {
    var res = false;
    var none = true;
    // Select checkbox element is id attribute contain 'idcheckitem'
    //var frm = jQuery("input:checkbox[id*=" + idcheckitem + "]");

    var isChecked = jQuery("input:checkbox[id*=" + idcheckitem + "]:checked").length;
    if (isChecked > 0) none = false;

    if (none == true) {
        alert("You currently have no data selected.");
        return false;
    } else {
        return (confirm("Are you sure you want to delete this? This will be deleted immediately, and there is no undo facility. Please click OK to delete or Cancel."));
    }
}

function confirmDelete1()
{
    return confirm("Are you sure you want to delete this? This will be deleted immediately, and there is no undo facility. Please click OK to delete or Cancel.");
}

function isNumeric(obj)
{
    return /^\d+$/.test(obj);
}


//CtrlName.Attributes("onkeypress") = "return checknum(arguments[0] , 'd','" & CtrlName.ClientID & "')"
//CtrlName.Attributes("onkeypress") = "return checknum(arguments[0])"'
function checknum(e, n, values) {
    if (!e) {
        e = window.event;
    }
    
    if (typeof e.which == "number") {
        e = e.which;
    } else if (typeof e.keyCode == "number") {
        e = e.keyCode;
    } else if (typeof e.charCode == "number") {
        e = e.charCode;
    }
    
    if (e >= 48 && e <= 57 ||e == 13 || e == 8 || e == 0 || n == "d" && e == 46) {
        if ((e == 46 && values != "") && document.getElementById(values).value.indexOf(".") > -1){
            return false;
        } else {
            return true;
        }
    } else {
        return false;
    }
    
    var i = 1;
}

// CtrlName.Attributes("onblur") = "return changefloat('" & CtrlName.ClientID & "')"

function changefloat(txt)
{ var p = txt.value ;
  if ( p == '') { p = 0 ; }
  txt.value = parseFloat(p).toFixed(2) ;   
}
function trim(str){
    return str.replace(/^\s*/, "").replace(/\s*$/, "");
}

function inputEmpty(def,item) {
    if ( item.value == '' ){
        item.value = def;
    }
}

function inputnumempty(def,item) {
    if ( item.value == '' || item.value == 0){
        item.value = def;
    }
}

function htmlencode(str){
    str = str.replace("<","&lt;");
    str = str.replace(">","&gt;");
    return str;
}

function htmldecode(str){
    str = str.replace("&gt;",">");
    str = str.replace("&lt;","<");
    return str;
}

function openWindow(url, name, w, h, scl, p)
{
    w += 32;
    h += 20;
    wleft = (screen.width - w) / 2;
    wtop = ((screen.height - h) / 2) - 50;
    if (wleft < 0) {
        w = screen.width;
        wleft = 0;
    }
    if (wtop < 0) {
        h = screen.height;
        wtop = 0;
    }
    p += (",width=" + w + ",height=" + h + ",top=" + wtop + ",left=" + wleft + ",scrollbars=" + scl);
    var win = window.open(url, name, p);
    win.focus();
}

 function checkAll(idcheckall, idcheckitem) {
 
    var chk = document.getElementById(idcheckall);
    var bState = chk.checked;
   
    var frm = document.forms[0];
    for (i = 0; i < frm.length; i++) {
        var e = frm.elements[i];
        if (e.id.indexOf(idcheckitem) != -1) {
            e.checked = bState;
        }
    }
}
function checkAll_match(idcheckall, idcheckitem) {

    var chk = document.getElementById(idcheckall);
    var bState = chk.checked;
    var frm = jQuery("input:checkbox[id*=" + idcheckitem + "]");

    frm.each(function() {
        this.checked = bState;
    });
}
 function checkChanged(idcheckall, idcheckitem){
    var frm = document.forms[0];
    var bAllChecked = true;
        
    for (i = 0; i < frm.length; i++) {
        var e = frm.elements[i];
        if (e.id.indexOf(idcheckitem) != -1) {
            if (e.checked == false) bAllChecked = false; 
        }
    }
    
   // alert(idcheckall);
    var checkAll =  document.getElementById(idcheckall);
    if(bAllChecked) checkAll.checked = true; else checkAll.checked = false;
}

//get jQuery object from id of element
function jsget(ctrl) { return jQuery("#" + ctrl + ""); }

//call ajax from checkbox
function ajaxCheckBox(furl, callId, id, imgId, chkImg, nochkImg, waitImg)
{
    var img = jsget(imgId);
    if(img.attr("src") == waitImg) return;
    
    var checked = (img.attr("src") == chkImg);
    img.attr("src", waitImg);
    
    var qry = 'cid='+escape(callId)+'&id='+escape(id)+'&val='+escape(checked);
    jQuery.ajax({
        type: "GET",
        url: furl,
        data: qry,
        success: function(msg){
            if(msg == "1"){
                img.attr("src", chkImg);
            }else{
                img.attr("src", nochkImg);
            }
        },
        fail: function(msg){
            alert('ajaxCheckBox failed');
        }
    });




    var TierType = 0;

switch(escape(callId))
{
case  "GroupTierDisplay":
  TierType = 1;
  break;
case  "GroupTierDisplayTop":
  TierType = 1;
  break;  
case "TierDisplay":
   TierType = 2;
  break;
 case "SubTierDisplay":
  TierType = 3;
  break;
}

if (TierType > 0) {
   
    document.getElementById("iframeClearCache").src = "http://" + document.domain + "/Admincontrol/ClearCache/ClearCache.aspx?TierType=" + TierType + "&MainGroup=1";
}
}



function ajaxTextBoxBegin(lblId, txtId)
{
    jsget(lblId).css("display", "none");
    var jqrtxt = jsget(txtId);
    jqrtxt.css("display", "inline");
    var txt = jqrtxt.get(0);
    txt.focus();
    txt.select();
}
function ajaxTextBox(e, furl, callId, id, lblId, txtId, imgWaitId)
{
    var evt = e?e:window.event;
	  evt.cancelBubble = true;
	  if (evt.stopPropagation) evt.stopPropagation();
	
	  if(evt.keyCode == "13"){
        var lbl = jsget(lblId);
        var txt = jsget(txtId);
        var waitImg = jsget(imgWaitId);
        var oldval = lbl.html();
        var newval = txt.val();
        
        lbl.css("display", "none");
        txt.css("display", "none");
        waitImg.css("display", "inline");
        
        var qry = 'cid='+escape(callId)+'&id='+escape(id)+'&val='+escape(newval);
        jQuery.ajax({
            type: "GET",
            url: furl,
            data: qry,
            success: function(msg){
                if(msg == "1"){
                    lbl.html(htmlencode(newval));
                    txt.val(newval);
                    if(lbl.html() == "")
                    {
                        lbl.html("-");
                    }
                }else{
                    lbl.html(htmlencode(oldval));
                    txt.val(oldval);
                }
                lbl.css("display", "block");
                txt.css("display", "none");
                waitImg.css("display", "none");
            },
            fail: function(msg){
                alert('ajaxTextBox failed');
            }
            });
	}else if(evt.keyCode == "27"){
        jsget(lblId).css("display", "block");
        jsget(txtId).css("display", "none");
	}
}
function ajaxImageDel(furl, callId, imgid, id, key ,table, hplinkid,imgname, waitImg)
{

	if ( confirmDelete1()==false) {
	return false;
	}  
	
    var img = jsget(imgid);
	if (key!='filename' && img.attr("src")){
		  if(img.attr("src") == waitImg) return;
          img.attr("src", waitImg);
	}
  
    var hplink = jsget(hplinkid);
    var qry = 'cid='+escape(callId)+'&id='+escape(id)+'&table='+escape(table)+'&key='+escape(key)+'&Imgname='+escape(imgname);
	
    jQuery.ajax({
        type: "GET",
        url: furl,
        data: qry,
        success: function(msg){
           //img.attr("src","");
           
		   img.css("display", "none");
		   hplink.css("display", "none");
		   
        },
        fail: function(msg){
            alert('Delete Image failed');
        }
        });	 
}

function getXMLHTTP(){
    var A=null;
    try{
	    A=new ActiveXObject('Msxml2.XMLHTTP');
    }catch(e){
	    try{
		    A=new ActiveXObject('Microsoft.XMLHTTP');
	    }catch(oc){
		    A=null;
	    }
    }
	
    if(!A&&typeof XMLHttpRequest!='undefined'){
	    A=new XMLHttpRequest();
    }
    return A;
}

if (window.jQuery)
{

    var divx = jQuery("<div id='Datas' class='DivOverLayer'></div>");
}
// ajaxPopup ---------------------------------------
function ajaxPopup(e, url, width, ctl)
{
    var evt = e?e:window.event;
    initPopup(evt,width,url,ctl.id);
    showPopup(url,ctl.id);
}

function initPopup(evt,width,url,ctlID)
{
    InsertPopup(width,url,ctlID) ;
    divx.css("display","block");
    
    var posx = 0;
    var posy = 0;
    posx = evt.clientX; //+ document.body.scrollLeft
    posy = evt.clientY; //+ document.body.scrollTop
    posx -= (width +12);
    posy += 8; 

    divx.css("left",((posx < 15) ? 15 : posx) +'px');
    divx.css("top",(posy)+'px');   

    divx.css("left",((posx < 15) ? 15 : posx) +'px');
    divx.css("top",(posy) + 'px');  
}

function InsertPopup(width,url,ctlID)
{ 
    divx.css("width",width+"px");
    var hsp = (width-40)/2 ;
    
    divx.html("loading...");
    jQuery(document.body).append(divx); 
    divx.unbind("click");
    divx.bind("click",function(){jQuery(this).css("display","none");});
}

//HidePopup = function(){ div.css("display","none"); }

function showPopup(url,ctlID)
{   
    
    jQuery.ajax({
                    type: "GET",
                    url: url,
                    data: 'ctlId=' + ctlID,
                    success: function(msg){
                        divx.html(msg);
                    },
                    fail: function(msg){}
               });	 
}

// END ajaxPopup ---------------------------------------
