﻿//use diff variable to reference jQuery
var jq = jQuery;

function hrefto(loc){
	window.location = loc;
}
function stringFormat(str, parms){
    var tmp = str;
    for(var i=0;i<parms.length;i++){
        tmp = replaceAll(tmp, '{'+i+'}', parms[i]);
    }
    return tmp;
}

function replaceAll(str, from, to){
    var idx = str.indexOf( from );
    while ( idx > -1 ) {
        str = str.replace( from, to );
        idx = str.indexOf( from );
    }
    return str;
}

function TrimString(str) {
    str = str.replace(/^[ ]+(.*)$/, '1'); // Trims leading spaces
    str = str.replace(/^(.*)[ ]+$/, '$1'); // Trims trailing spaces
    return str;
}

function quickformsubmit(kvpairs, page, target){
    var qfid = "quickform_"+Math.round(Math.random()*10000);//must round because somehow a decimal in the number breaks the id or something
    
    if(!page)
        page = window.location;
    if(!target)
        target = "_self";
    var formtop = "<form method=\"post\" id=\""+qfid+"\" name=\""+qfid+"\" action=\""+page+"\" target=\"" + target + "\">";
    for(var i=0;i<kvpairs.length;i++){
        
        formtop+= "<input type=\"hidden\" name=\""+kvpairs[i][0]+"\" value=\""+kvpairs[i][1]+"\" />";
    }
    formtop+= "</form>";
    //alert(formtop);
    jQuery("body").append(formtop);
    //alert(jQuery("#"+qfid).size());
    //jQuery("#"+qfid).get(0).submit();
    document.forms[qfid].submit();

}


