// $Id: common.js.php,v 1.2 2009/08/27 08:08:05 jatin Exp $



function confirmDel(msgDel){
	if(confirm(msgDel)) {
		return true;
	}
	return false;

}

//For open pop up window
function openpopup (popurl) {
 	var winpops = window.open(popurl,"","width=770,height=450,menubar=0,toolbar=0,scrollbars =1");
	winpops.focus();
}

function errorJS(){
		window.location.href="/seller/item#top";
	}
	function cancelJS(){
		window.location.href="'.sfConfig::get('app_webpath').'";
	}
	function depositJS(deposit_type){
		if(deposit_type.value == "Y")
			document.getElementById("deposits").style.display="block";
		else
			document.getElementById("deposits").style.display="none";
	}
	function contactJS(contact_type){
		if(contact_type.value == "N")
			document.getElementById("contact_inf").style.display="block";
		else
			document.getElementById("contact_inf").style.display="none";
	}
	function productAvaJS(prd_availabe){
		if(prd_availabe.value == 2)
			document.getElementById("product_ava").style.display="block";
		else
			document.getElementById("product_ava").style.display="none";
	}

	function blockError(){return true;}
		window.onerror = blockError;

	function CategoryChanged(CONTROL){
		return CONTROL.options[CONTROL.selectedIndex].value+",+";
	}
	function loadSection(url,CONTROL) {
		var strTmp=CategoryChanged(CONTROL);
	    var strTmp=strTmp.split(",");
	    if(strTmp[0]==0)
	    	removeOptionAll("id_item_section")
	    url=url+"/id/"+strTmp[0];

	    new Ajax.Request(url, {asynchronous:true, evalScripts:true, onComplete:function(request, json){updateJSON(request, json, 2, strTmp[1])}});
	    return false;
	}
	function addOption(objSelectNow,txt,val)
	{
	    var objOption = document.createElement("OPTION");
	    objOption.text= txt;
	    objOption.value=val;
	    objSelectNow.options.add(objOption);
	}
	function addOptionGroup(selectId,optGroup)
	{
			var objSelect = document.getElementsByTagName("SELECT");
	    var objSelectNow = objSelect[selectId];
	    if (selectId=="id_item_category_add"){
	        objSelectNow.length = 1;
	    }
	        for (i=0; i<optGroup.length; i++)
	        {
	            addOption(objSelectNow, optGroup[i][1], optGroup[i][0]);
	        }
	}
	function removeOptionGroup(selectId,optGroup)
	{
	    var objSelect = document.getElementsByTagName("SELECT");
	    var objSelectNow = objSelect[selectId];
	    for (i=0;i<objSelectNow.length;i++){
	        if (objSelectNow.options[i].value==optGroup[0][0]){
	            var bgn=i;
	            break;
	        }
	    }
	    for (i=0;i<optGroup.length;i++){
	        objSelectNow.options.remove(bgn);
	    }
	}
	function removeOptionAll(selectId)
	{
	    var objSelect = document.getElementsByTagName("SELECT");
	    var objSelectNow = objSelect[selectId];
	    for (i=1;i<objSelectNow.options.length;){
	        objSelectNow.remove(i);
	    }
	}
	function updateJSON(request, json,level,operation){
		 var responses = json;
	    if (!json){
	      var responses = eval("(" + request.responseText + ")");
	    }
	    if (level==1)
	        addOptionGroup("id_item_category_add",responses);
	    else if (level==2){
	    	  if (operation=="+"){
	    	  		removeOptionAll("id_item_section");
	            addOptionGroup("id_item_section",responses);
	        }
	        else if (operation=="-"){
	            removeOptionGroup("id_item_section",responses);
	        }
	        else if (operation=="--"){
	            removeOptionAll("id_item_section");
	        }
	    }
	}

function createNIDForm(idUser)
{    alert('ere');
    xmlHttp = GetXmlHttpObject();
	if (xmlHttp==null){
		alert('Browser does not support HTTP Request');
	}

	var readUrl = location.protocol+'//'+location.hostname+'/northid/createNIDViewForm/idUser/'+idUser;

	/* Calling php page through ajax */
	xmlHttp.open('GET',readUrl,true);
	xmlHttp.send(null);


    //var strIdUser='strIdUser='+idUser;
    //alert(location.protocol+'//'+location.hostname+'/northid/createNIDViewForm');

    //new Ajax.Request(location.protocol+'//'+location.hostname+'/product/list/6',{asynchronous:true, parameters:strIdUser,
    /*new Ajax.Request('http://kvl.irentlive.svs7/product/list/6',{asynchronous:true, parameters:strIdUser,
                            method: 'get',
                            contentType: 'text/html',
                            onSuccess: function(responseReq)
                            {
                                document.getElementById('nidReqUser').innerHTML='';
                                document.getElementById('nidReqUser').innerHTML=responseReq.responseText;
                                document.listNorthId.submit();
                            }
                        }
                    );*/

    return false;
}

function GetXmlHttpObject(){
	var xmlHttp=null;
	try	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	} catch (e) {

	//Internet Explorer
	try	{
		xmlHttp=new ActiveXObject('Msxml2.XMLHTTP');
		} catch (e) {
			xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');
		}
	}
	return xmlHttp;
}


